PHP provides a large number of predefined variables. Because many variables depend on the version and settings of the server that is running, and other factors, no detailed documentation is provided. Some of the predefined variables do not take effect when PHP is run as a command line. For a detailed list of these variables
User-defined predefined variables
| The code is as follows |
Copy Code |
echo "Current operating system Information". Php_os. " "; Echo ' This file path and file name is: '. __file__. ' '; echo "Current PHP version information". Php_version. " "; ?> |
System pre-defined variables
$GLOBALS
Contains a reference to a globally valid variable that refers to each current script. The key name of the array is the name of the global variable. $GLOBALS array exists starting with PHP 3.
$_server
Variables are set by the Web server or directly associated with the execution environment of the current script. Similar to the old array $HTTP _server_vars array (still valid but opposed to use).
$_get
A variable that is submitted to the script via a URL request. Similar to the old array $HTTP _get_vars array (still valid but opposed to use).
$_post
A variable that is submitted to the script via the HTTP POST method. Similar to the old array $HTTP _post_vars array (still valid but opposed to use).
$_cookie
A variable that is submitted to the script via the HTTP cookie method. Similar to the old array $HTTP _cookie_vars array (still valid but opposed to use).
$_files
A variable that is submitted to the script via an HTTP POST file upload. Similar to the old array $HTTP _post_files array (still valid but opposed to use). For more information, see POST method uploads.
$_env
Executes the variables that the environment submits to the script. Similar to the old array $HTTP _env_vars array (still valid but opposed to use).
$_request
The variable that is submitted to the script via the get,post and COOKIE mechanism, so the array is not trustworthy. The presence or absence of all variables contained in the array and the order of the variables are defined by the Variables_order configuration instructions in php.ini. This array does not have a direct corresponding version before PHP 4.1.0. See Import_request_variables ().
Since PHP 4.3.0, the file information in $_files no longer exists in $_request.
Note: This array will not contain argv and ARGC entries when running in command-line mode; they already exist in the array $_server.
$_session
The variable currently registered to the script session. Similar to the old array $HTTP _session_vars array (still valid but opposed to use).
$_server[' Php_self ']
The file name of the currently executing script, which is related to document root. For example, using $_server[' php_self ' in a script with a URL address of Http://example.com/test.php/foo.bar will give the result/test.php/foo.bar. If PHP is running as a command line, the variable is not valid.
$_server[' server_name ']
The name of the server host where the script is currently running. If the script is running on a virtual host, the name is determined by the value set by that virtual host. For example, at the URL address of/test.php $_server[' server_name ') This result will be obtained.
Cases
| The code is as follows |
Copy Code |
User sent a GET header with key = Secret_access, val = true, so echo $_get["Secret_access"]; Output:true echo $secret _access; Output Session_Start (); In previous logic, you set session variable $secret _access = False echo $_session["Secret_access"]; Output:false echo $secret _access; Output:false Extract_globals (); Globals put into "normal" variables echo $_get["Secret_access"]; Output:true echo $_session["Secret_access"]; Output:false echo $secret _access; Output:true VARIABLES is compromised! Don't use $secret _access! Use $_session["secret_access"] instead!!! ?> |
http://www.bkjia.com/PHPjc/628760.html www.bkjia.com true http://www.bkjia.com/PHPjc/628760.html techarticle PHP provides a large number of predefined variables. Because many variables depend on the version and settings of the server that is running, and other factors, no detailed documentation is provided. Some pre-defined variables ...