PHP super global variables summary, php global variables
Summary of important PHP super global variables in silicon1985
PHP has nine predefined variable arrays, which are summarized as follows:
1. $ _ SERVER
The $ _ SERVER super global variable contains information created by the web SERVER. It provides information about the SERVER and the customer configuration and the current request environment. The variable values in $ _ SERVER differ from the number of variables on the SERVER. However, variables defined in CGI1.1 can be found generally. Including:
$ _ SERVER ['HTTP _ referer']; The URL that directs the user to the page at the current location;
$ _ SERVER ['remote _ ADDR ']; customer IP address;
$ _ SERVER ['request _ URI ']; URL path. 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 the parameters passed using the GET method. If the requested URL is a [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, $ _ GET is the only way to access the variables passed through the GET method.
3. $ _ POST
The $ _ POST super global variable contains information about the parameters passed using the POST method.
<Form caction = "subscribe. php" method = "post">
<P>
Email address: <br>
<Input type = "text" name = "email" size = "20" maxlength = "so" value = "">
</P>
<P>
Password: <br>
<Input type = "password" name = "pswd" size = "20" maxlength = "15" value = "">
</P>
<P>
<Input type = "submit" name = "subscribe" value = "subscribe! ">
</P>
</Form>
By using the script subscribe. php, you can use the following POST variable:
$ _ POST ['e-mail '] = "jason@example.com ";
$ _ POST ['pswd '] = "rainyday ";
$ _ POST ['subscribe'] = "subscribe! ";
Like $ _ GET, $ _ POST is the only way to access the POST variable by default.
4. $ _ COOKIE
$ _ COOKIE the super global variable stores the information transmitted to the script through HTTP cookie. These cookies are generally set by the setcookie () function of the previously executed PHP script. For example, if setcookie () is used to store a cookie named example.com with a value of ab2213. You can obtain this value by calling $ _ COOKIE ['example.com.
5. $ _ FILES
The $ _ FILES super global variable contains information about the data uploaded to the server through the POST method. This super global variable is different from other variables. It is a two-dimensional array containing five elements. The first subscript indicates the name of the file upload element in the form. The second subscript is one of the five pre-defined subscripts, which describe a property of the file to be uploaded:
△$ _ FILES ['upload-name'] ['name']; file name uploaded from the client to the server;
△$ _ FILES ['upload-name'] ['type']; MIME type of the uploaded file. Whether the value of this variable is assigned depends on the function of the browser.
△$ _ FILES ['upload-name'] ['SIZE']; size of the uploaded file (in bytes );
△$ _ FILES ['upload-name'] ['tmp _ name']; temporary name assigned before the file is uploaded to the final location.
△$ _ FILES ['upload-name'] ['error']; upload status code. Although this variable is named error, it will be filled in if it is successful. It has five possible values:
■ The UPLOAD_ERR_ OK file is successfully uploaded.
■ The size of the UPLOAD_ERR_INI_SIZE file exceeds the maximum value specified by the upload_max_filesize command.
■ The size of the UPLOAD_ERR_FORM_SIZE file exceeds the maximum value specified by MAX_FILE_SIZE to hide the form field parameter (optional.
■ Only part of the UPLOAD_ERR_PARTIAL file is uploaded.
■ No file specified in the UPLOAD_ERR_NO_FILE upload form
6. $ _ ENV
The $ _ ENV super global variable provides PHP to parse information about the server environment. The variables in this array include:
△ $ _ ENV ['hostname'] server host name
△$ _ ENV ['shell'] System SHELL
7. $ _ REQUEST
$ _ REQUEST is an all-powerful global variable that records the variables passed to the script through various methods, especially GET, POST, and COOKIE. The order of these variables does not depend on the order they appear in the sending script, but on the order specified by the variables_order configuration command. We recommend that you use this super variable because it is not safe enough.
8. $ _ SESSION
The $ _ SESSION super global variable contains information related to all sessions. Registering session information can be convenient for you, so that you can reference the session information throughout the website without passing data through the GET or POST display.
9. $ GLOBALS
The $ GLOBALS super global variable array can be considered as a superset of super global variables, including all variables in the global scope. Run the following code to view all the variables in $ GLOBALS.
Print '<pre> ';
Print_r ($ GLOBALS );
Print '</pre> ';