background preloader

PHP

Facebook Twitter

Drupal

PHP Variables passed by value or by reference. Extending Exceptions. <?

Extending Exceptions

Juan Treminio - Dallas PHP/MySQL Web Developer — Composer Namespaces in 5 Minutes. Install MySQL Server 5 on Ubuntu. PHP string to int. Logging With PHP. I have to warn you not to be misled by the title of this article.

Logging With PHP

It isn't really about cutting down trees with PHP. I know that PHP is the Swiss Army knife of Web scripting languages, but I don't think its developers have come up with a way to have it reduce our tree cover (at least not yet). Rather, this article is about a different sort of logging - the sort which involves writing messages to files or devices on a regular basis, and using these messages to "do something useful", be it generating a report or building an audit trail for activity tracking. Over the next few pages, I'm going to take a quick look at the various mechanisms available to log script activity via PHP, demonstrating both built-in functions and add-on classes that allow you to add logging functionality to your applications. Using PHP_SELF in the action field of a form. In this article shows the usage of PHP_SELF variable and how to avoid PHP_SELF exploits.

Using PHP_SELF in the action field of a form

What is PHP_SELF variable? PHP_SELF is a variable that returns the current script being executed. This variable returns the name and path of the current file (from the root folder). You can use this variable in the action field of the FORM. There are also certain exploits that you need to be aware of. A) Suppose your php file is located at the address:

Symfony

Doctrine. How to send correct UTF-8 mail in PHP. Optimal bcrypt work factor. Simple PHP 5.3+ Bcrypt class and functions. Get json using php. Json_decode. My initial problem was to have PHP check a form in case JavaScript was disabled on the client.

json_decode

I fiddled with json_decode for a while before realizing what I really wanted: to be able to initialize the same object in PHP and JavaScript from a common source file. I ended up writing a tiny parser for a JavaScript object initializer, which is close to - but not the same thing as - a piece of JSON. Among other things, it - recognizes regexes (turning them into PHP strings), - handles C/C++ comments - accepts non-quoted field names. This parser will accept a superset of real JS object initializer syntax (for instance non-quoted string litterals or improperly formed regexes). Error report and sanity checks are close to non-existent. Here is the code for those who are interrested : define ('JSVAL_TEXT' , 12001); define ('JSVAL_STRING', 12002); define ('JSVAL_REGEXP', 12003); define ('JSVAL_COMMT1', 12004); define ('JSVAL_COMMT2', 12005);

Handling JSON like a boss in PHP. There are already lots of tutorials out there on handling JSON with PHP, but most of them don’t go much deeper than throwing an array against json_encode and hoping for the best.

Handling JSON like a boss in PHP

This article aims to be a solid introduction into JSON and how to handle it correctly in combination with PHP. Also, readers who don’t use PHP as their programming language can benefit from the first part that acts as a general overview on JSON. JSON (JavaScript Object Notation) is a data exchange format that is both lightweight and human-readable (like XML, but without the bunch of markup around your actual payload). Its syntax is a subset of the JavaScript language that was standardized in 1999.

If you want to find out more, visit the official website. The cool thing about JSON is that you can handle it natively in JavaScript, so it acts as the perfect glue between server- and client-side application logic. Introducing JSON So, what datatypes does JSON support? Here’s a example JSON document: Handling data in a PHP JSON Object. Klassen und Objekte. Maybe someone will find these classes, which simulate enumeration, useful.

Klassen und Objekte

<? File Read. My apologies for taking so long to actually get to the point where you get information from files. In this lesson we will teach you how to read data from a file using various PHP functions. Before we can read information from a file we have to use the function fopen to open the file for reading. Here's the code to read-open the file we created in the PHP File Write lessons. File Write. Now that you know how to open and close a file, lets get on to the most useful part of file manipulation, writing!

File Write

There is really only one main function that is used to write and it's logically called fwrite. Before we can write information to our test file we have to use the function fopen to open the file for writing. PHP Code: Php $_REQUEST vs $_GET and $_POST.