- Part 1: Console Input and Output
- Part 2: File Input and Output
- Part 3: Server-side Usage
- Part 4: Working with Composer
PHP: Hypertext Preprocessor (PHP) is a server-side scripting language frequently used as part of web development and as a command-line tool for common tasks.
In its role as a “hypertext preprocessor,” PHP is often paired with server software like Apache or nginix. Frequently, these combinations are called LAMP (Linux, Apache, MySQL, and PHP) or LEMP (Linux, Nginix, MySQL, and PHP).
As part of the server software, PHP is used as a scripting language to respond to server requests through processing data, serving files, or connecting to other services like databases.
Responding to Data
Depending on how data is sent to a HTTP server, it is often either a GET or POST request. Very broadly defined as “getting” and “putting,” these types of requests correspond to two superglobals (variables that can be accessed anywhere) in PHP called $_GET and $_POST.
When data is sent as a GET request, it can be found as an associative array of the key and its value. The same is also true of POST and the $_POST variable.
Starting with PHP 4.1, the superglobal $_REQUEST was added to capture data in both $_GET and $_POST. In most cases, it is safer, and generally recommended, to access the data through $_REQUEST unless the access method is important.
Sending Data Back
When acting with web server software, the functions that would have written data to the console will now “write” back to the page requesting it. In more advanced or complex projects, this could be JSON, XML, or text.
When PHP is embedded in or with HTML content, it will also “write” to the page as it appears in the order it appears in the page. This can often be convenient when using PHP to dynamically include parts of a page or react in some way to things like cookies or other environmental variables and data.