Many of the predefined variables in PHP are "hyper-global", which means they are available in all scopes of a script. There is no need to perform a global $variable in a function or method; You can access them.
These hyper-global variables are:
$GLOBALS
$_server
$_request
$_post
$_get
$_files
$_env
$_cookie
$_session
This paper mainly introduces PHP9 super global variables
1, $_server
The $_server Super global variable contains information created by the Web server that provides information about the server and client configuration and the current request environment. Depending on the server, the variable value and the number of variables in the $_server are different, but the variables defined in the CGI1.1 specification can generally be found. These include:
$_server[' Http_referer ']; The URL of the page that guides the user to the current location;
$_server[' REMOTE_ADDR ']; Customer IP address;
$_server[' Request_uri ']; The path portion of the URL. If the URL is [Url]http://www.example.com/blog/apache/index.html[/url], then the URI is/blog/apache/index.html.
$_server[' Http_user_agent ']; The customer's user agent generally provides information about the operating system and the browser.
2, $_get
The $_get Super global variable contains information about parameters passed using the GET method. If the request URL is [Url]http://www.example.com/index.html?cat=apache&id=157[/url], you can use the $_get Super global variable to access the following variables:
$_get[' cat '] = "Apache";
$_get[' id '] = "157";
By default, the $_get Super global variable is the only way to access the variables passed by the pass get method.
3, $_post
The $_post Super global variable contains information about the parameters passed by the Post method.
The code is as follows:
<form caction= "subscribe.php" method= "POST" > <p> Email Address: <br> <input type= "text" Name= "Email" size= "maxlength=" So "value=" "> </p> <p> Password: <br> <input type= "Password" name= "pswd" size= "maxlength=", "value=" "> </p> <p> <input type= " Submit "Name=" subscribe "value=" subscribe! " > </p></form>
With script subscribe.php, you can use the following post variables:
$_post[' email ' = "jason@example.com"; $_post[' pswd '] = "rainyday"; $_post[' subscribe '] = "subscribe!";
As with $_get, by default, the $_post Super global variable is the only way to access the post variable.
4, $_cookie
The $_cookie Super global variable stores information passed to the script via an HTTP COOKIE. These cookies are generally set by PHP functions Setcookie (), which were previously executed by PHP scripts. For example, suppose you use Setcookie () to store a cookie named example.com with a value of ab2213. This value can then be obtained by calling $_cookie[' example.com '].
5, $_files
The $_files Super global variable contains information about the data that is uploaded to the server via the Post method. This super global variable differs from the other variables, which is a two-dimensional array that contains 5 elements. The first subscript indicates the file upload element name of the form; The second subscript is one of five predefined subscripts that describe a property of the uploaded file:
$_files[' upload-name ' [' name ']; File name for uploading files from client to server; $_files[' upload-name ' [' type ']; The MIME type of the uploaded file, whether or not the variable is assigned depends on the browser's functionality. $_files[' upload-name ' [' Size ']; The size of the uploaded file in bytes; $_files[' upload-name ' [' tmp_name ']; After uploading, move this file to the temporary name given before the final location. $_files[' upload-name ' [' Error ']; Upload status code. Although the variable is named error, it is actually filled in the case of success. It has five possible values: The Upload_err_ok file successfully uploaded the Upload_err_ini_size file size exceeds the maximum value specified by the upload_max_filesize directive. The upload_err_form_size file size exceeds the maximum value specified by the Max_file_size hidden form field parameter (optional). The upload_err_partial file only uploads a portion of the Upload_err_no_file upload form without the specified file
6, $_env
The $_ENV Super global variable provides information about the server environment in which php resolves. The variables in this array include:
$_env[' HOSTNAME ' host name of server
$_env[' shell '] system shell
7, $_request
The $_request Super global variable is a versatile player that records variables passed to the script in various ways, especially get, POST, and COOKIE. The order of these variables does not depend on the order in which they appear in the sending script, but rather depends on the order specified by the Variables_order configuration directives. It is recommended to use this super variable sparingly because it is not secure enough.
8, $_session
The $_session Super global variable contains information about all sessions. Registering session information provides you with the convenience of referencing these session information throughout the site without the need to pass data through a GET or post display.
9. $GLOBALS
The $GLOBALS Super global variable array can be thought of as a superset of the super global variables, including all variables within the global scope. Execute the following code to see all the variables in the $globals.
print ' <pre> '; Print_r ($GLOBALS); print ' </pre> ';