Lecture
PHP provides a large number to any running script. predefined variables . However, many of these variables cannot be fully documented, as they depend on the server running, its version and settings, as well as other factors. Some of these variables are not available when running PHP from the command line.
A quick note: since PHP 4.2.0, the value of the register_globals directive is set to off by default. This is a big change in PHP. The register_globals position of off makes predefined variables available in the global scope. For example, to get DOCUMENT_ROOT , you will need to use $ _SERVER ['DOCUMENT_ROOT'] instead of $ DOCUMENT_ROOT , or $ _GET ['id'] from the URL http://www.example.com/test.php?id=3 instead of $ id , or $ _ENV ['HOME'] instead of $ HOME .
Since version 4.1.0, PHP provides an additional set predefined arrays containing web server variables (if available), environments, and user input. These new arrays are special because they are automatically global. That is, automatically available in any scope. For this reason, they are also known as 'autoglobal' or 'superglobal' variables. (In PHP, there is no mechanism for user-defined superglobal variables)
PHP Superglobals
Contains a link to each variable currently available in the global scope of the script. The keys of this array are the names of global variables. $ GLOBALS exists since PHP 3.
Variables set by the web server or directly related to the current script execution environment. Analogue of the old array $ HTTP_SERVER_VARS (which is still available, but not recommended).
Variables transmitted to the script via HTTP GET. Analogue of the old array $ HTTP_GET_VARS (which is still available, but not recommended).
Variables transmitted to the script via HTTP POST. Analogue of the old $ HTTP_POST_VARS array (which is still available, but not recommended).
Variables transmitted to the script via HTTP cookies. Analogue of the old array $ HTTP_COOKIE_VARS (which is still available, but not recommended).
Variables transmitted to the script via HTTP post-upload files. Analogue of the old $ HTTP_POST_FILES array (which is still available, but not recommended). See POST loading for more information.
Variables passed to the script through the environment. Analogue of the old array $ HTTP_ENV_VARS (which is still available, but not recommended).
Variables passed to the script via the GET, POST, and COOKIE input mechanisms, and which therefore cannot be trusted. The presence and order of variable inclusion in this array is determined in accordance with the PHP variables_order configuration directive. This array has no direct analogues in versions of PHP prior to 4.1.0. See also import_request_variables () .
Variables that are currently registered in the script session. Analogue of the old array $ HTTP_SESSION_VARS (which is still available, but not recommended). For more information, see Session Handling Functions.
Comments
To leave a comment
Running server side scripts using PHP as an example (LAMP)
Terms: Running server side scripts using PHP as an example (LAMP)