PHP pre-defined variable 9: Usage of ultra-global array, global array _ PHP Tutorial

Source: Internet
Author: User
Tags http cookie
PHP pre-defined variable 9 Super Global array usage details, global array. PHP pre-defined variables 9: Usage of ultra-Global Arrays. Global Arrays 1 and $ _ SERVER Super global variables contain information created by the web SERVER, it provides server and customer configuration and PHP predefined variable 9 Super Global array usage details, global array

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 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, $ _ 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.

The code is as follows:

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:

UPLOAD_ERR_ OK file uploaded successfully

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.

The code is as follows:
Print'

';  

print_r ($GLOBALS);

print '
';

Tip 1, $ _ SERVER Super global variables contain information created by the web SERVER, which provides SERVER and customer configurations and...

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.