Predefined Variables Related to HTTP Requests

This section describes predefined variables, $_GET, $_POST, $_COOKIE, $_REQUEST, and $_SERVER, that contains information included in the HTTP request received by the PHP engine from the Web server.

When the PHP engine is used on a Web server to handle a HTTP request, it converts information submitted in the HTTP request as predefined variables and pass them to PHP script.

1. $_GET - Associate array of HTTP request information submitted with the GET method. By default, all browsers submit HTTP requests with the GET method. Input information collected from Web page forms will be organized into pairs of names and values, which will be attached to the end of the URL in the first line of the HTTP request.

When the PHP engine receives a HTTP request, it will take those pairs of names and values from the end of the request URL and store them in the $_GET array as keys and values.

2. $_POST - Associate array of HTTP request information submitted with the POST method. If a Web page uses the POST method to submit input information collected from its form. The browser will organize input into names and values and attach them as the HTTP request body.

When the PHP engine receives a HTTP request, it will take those pairs of names and values from the request body and store them in the $_POST array as keys and values.

3. $_COOKIE - Associate array of submitted as cookies in the HTTP request. If a browser has cookies received previously from a Web server, it will automatically attach them in the next HTTP request to the same Web server.

When the PHP engine receives a HTTP request, it will take cookie names and cookie values from the request and store them in the $_POST array as keys and values.

4. $_REQUEST - Associate array of all elements from $_GET, $_POST, and $_COOKIE. To help you to get HTTP request input information in a single place, the PHP engine automatically combines all keys and values from $_GET, $_POST, and $_COOKIE into $_REQUEST.

5. $_SERVER - Associate array of information from the Web server and the HTTP request. When the PHP engine receives a HTTP request, it will take other information included in the request and store it in the $_SERVER array as keys and values. For example, the following keys and values represent information received from the HTTP request:

   REDIRECT_HANDLER = application/x-httpd-php
   REDIRECT_STATUS = 200
   HTTP_HOST = localhost
   HTTP_CONNECTION = keep-alive
   HTTP_UPGRADE_INSECURE_REQUESTS = 1
   HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.1; Win64; x64) ...
   HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;..
   HTTP_REFERER = http://localhost/
   HTTP_ACCEPT_ENCODING = gzip, deflate, br
   HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.9
   ......

The PHP engine also gathers additional information from the Web server and store it in the $_SERVER array as keys and values. For example, the following keys and values represent information received from the Web server:

   SERVER_SIGNATURE =
   SERVER_SOFTWARE = Apache/2.4.37 (Win64)
   SERVER_NAME = localhost
   SERVER_ADDR = ::1
   SERVER_PORT = 80
   REMOTE_ADDR = ::1
   DOCUMENT_ROOT = C:/apache/htdocs
   REQUEST_SCHEME = http
   CONTEXT_PREFIX = /cgi-bin-php/
   CONTEXT_DOCUMENT_ROOT = /local/php/
   ......

The PHP engine also gathers additional information from the operating system where the PHP engine is running and store it in the $_SERVER array as keys and values. For example, the following keys and values represent information received from the operating system:

   SystemRoot = C:\windows
   COMSPEC = C:\windows\system32\cmd.exe
   PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
   WINDIR = C:\windows
   ...

Table of Contents

 About This Book

 Introduction and Installation of PHP

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

Retrieving Information from HTTP Requests

Predefined Variables Related to HTTP Requests

 Operating System Information in $_SERVER

 Web Server Information in $_SERVER

 Information in $_GET and $_REQUEST

 Registering $_REQUEST Keys as Global Variables

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 Managing File Upload

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Parsing and Managing HTML Documents

 Configuring and Sending Out Emails

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Archived Tutorials

 References

 Full Version in PDF/EPUB