- PHP automatically creates variables for all the data it receives in an HTTP
request. This can include GET data, POST data, cookie data, and environment
variables. The variables are either in PHP's global symbol table or in one of a
number of superglobal arrays, depending on the value of the
register_globals setting in your php.ini
file.
-
-
- $_GET
-
GET-method variables. These are the variables supplied directly
in the URL. For example, with http://www.test.com/page.php?a=21&b=22,
$_GET['a'] and $_GET['b'] are set to 21 and 22, respectively.
- $_POST
-
POST-method variables. Form field data from regular POST-method
forms.
- $_COOKIE
-
Any cookies the browser sends end up in this array. The name of
the cookie is the key and the cookie value becomes the array value.
- $_REQUEST
-
This array contains all of these variables (i.e., GET, POST,
and cookie). If a variable appears in multiple sources, the order in which they
are imported into $_REQUEST is given by the setting of the
variables_order php.ini directive. The
default is 'GPC', which means GET-method variables are imported first,
then POST-method variables (overriding any GET-method variables of the same
name), and finally cookie variables (overriding the other two).
- $_SERVER
-
These are variables set by your web server. Traditionally
things like DOCUMENT_ROOT, REMOTE_ADDR, REMOTE_PORT,
SERVER_NAME, SERVER_PORT, and many others. To get a full list,
have a look at your phpinfo( ) output, or run a script like the
following to have a look:
<?php
foreach($_SERVER as $key=>$val) {
echo '$_SERVER['.$key."] = $val<br>\n";
}
?>
- $_ENV
-
Any environment variables that were set when you started your
web server are available in this array.