Summary of important PHP super global variables

Source: Internet
Author: User

Summary of important PHP super global variables

2008-07-14 16:53:03Label: global variable

[Push to technical circle
]

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. In $ _ server
The variable value differs from the number of variables, but the variables defined in the cgi1.1 specification can be found generally. These include: $ _ server ['HTTP _ referer']; URL of the page that directs the user to 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]
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. 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. 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> with 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, by default, the $ _ post super global variable is the only way to access the post variable. 4. $ _ cookie the super global variable is stored through HTTP
Cookie Information passed to the script. These cookies are generally set by the setcookie () function of the previously executed PHP script. For example, assume that
Setcookie () stores a cookie named example.com with a value of ab2213. You can call $ _ cookie ['later ['
Example.com '] to obtain this value. 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 5 elements.
. The first subscript indicates the name of the file to be uploaded in the form. The second subscript is one of the five pre-defined subscripts, which describe an attribute of the file to be uploaded: △
$ _ FILES ['upload-name'] ['name'];
File Name uploaded from the client to the server; △
$ _ FILES ['upload-name'] ['type'];
The 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'];
The temporary name assigned before the file is uploaded and moved 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: ■
Upload_err_ OK File Uploaded
The size of the upload_err_ini_size file exceeds
The maximum value specified by the upload_max_filesize command. ■
Upload_err_form_size
The file size 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. ■
The file 6 and $ _ env super global variables are not specified in the upload_err_no_file upload form to provide information about PhP parsing the server environment. The variables in this array include: △
$ _ Env ['hostname'] server host name △
$ _ Env ['shell'] System Shell 7, $ _ Request super global variable is an all-powerful player, which records the variables passed to the script through various methods, in particular, 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 $ _ Session
Super global variables contain information related to all sessions. Registering session information can help you easily reference this session information on the entire website without passing through the get or post display.
Data. 9. $ globals
A 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> ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.