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:

   CONTENT_LENGTH = 0
   HTTP_ACCEPT = */*
   HTTP_ACCEPT_LANGUAGE = en-us
   HTTP_ACCEPT_ENCODING = gzip, deflate
   HTTP_CONNECTION = Keep-Alive
   OS = Windows_NT
   ORIG_PATH_INFO = /HttpRequestDetails.php
   ORIG_SCRIPT_NAME = /HttpRequestDetails.php
   REQUEST_METHOD = GET
   ......

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:

   GATEWAY_INTERFACE = CGI/1.1
   NUMBER_OF_PROCESSORS = 1
   ProgramFiles = C:\Program Files
   SERVER_NAME = localhost
   SERVER_PORT = 80
   SERVER_PORT_SECURE = 0
   DOCUMENT_ROOT = c:/inetpub/wwwroot
   SCRIPT_FILENAME = c:\inetpub\wwwroot\HttpRequestDetails.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:

   CLIENTNAME = Console
   ComSpec = C:\WINDOWS\system32\cmd.exe
   HOMEDRIVE = C:
   PHPRC = c:php
   PROCESSOR_ARCHITECTURE = x86
   SystemDrive = C:
   SystemRoot = C:\WINDOWS
   PHP_SELF = HttpRequestDetails.php

Last update: 2015.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.0

 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

 Configuring and Sending out Emails

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

 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

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials

 References

 PDF Printing Version