PHP predefined variable 9 large Super Global array usage detailed _php basics

Source: Internet
Author: User
Tags http cookie setcookie

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, there is a difference in the number of variables and variables in the $_server, although the variables defined in the CGI1.1 specification can generally be found. These include:

$_server[' Http_referer ']; The URL of the page that directs 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 ']; Customer's user agent, which typically provides information about the operating system and the browser.

2, $_get

The $_get Super global variable contains information about the parameters that are 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 variable:

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

Copy Code code 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>

Using the script subscribe.php, you can use the following post variable:

$_post[' email ' = "jason@example.com";

$_post[' pswd ' = "rainyday";

$_post[' subscribe ' = "subscribe!";

As with $_get, the $_post Super global variable is the only way to access post variables by default.

4, $_cookie

The $_cookie Super global variable stores information passed to the script via an HTTP COOKIE. These cookies are typically set by PHP functions Setcookie () that were previously executed by PHP scripts. For example, suppose you use Setcookie () to store a cookie named example.com, with a value of ab2213. You can then get this value 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 other variables in that it is a two-dimensional array that contains 5 elements. The first subscript identifies the form's file upload element name; The second subscript is one of five predefined subscripts that describe an attribute of the uploaded file:

$_files[' upload-name ' [' name ']; The file name to upload files from the client to the server;

$_files[' upload-name ' [' type ']; The MIME type of the uploaded file, and whether the variable is assigned depends on the browser's capabilities.

$_files[' upload-name ' [' Size ']; The size (in bytes) of the uploaded file;

$_files[' upload-name ' [' tmp_name ']; After uploading, move the file to the temporary name given before the final location.

$_files[' upload-name ' [' Error ']; Upload status code. Although this variable is named error, it is actually filled out in the case of success. It has five possible values:

Upload_err_ok file uploaded successfully

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).

Upload_err_partial file only uploaded part of

Upload_err_no_file file not specified in upload form

6, $_env

The $_ENV Super global variable provides information about the server environment in which php resolves. The variables in this array include:

Host name of the $_env[' HOSTNAME ' server

$_env[' shell '] system shell

7, $_request

The $_request Super global variable is a versatile player that records variables passed to the script in a variety of ways, especially get, POST, and cookies. The order of these variables does not depend on the order in which they appear in the send script, but rather on the order specified by the Variables_order configuration directives. It is recommended that you use this super variable less because it is not safe enough.

8, $_session

The $_session Super global variable contains information about all sessions. Registering session information can be convenient for you so that you can refer to the session information throughout your Web site without having to pass the data through get or post display.

9, $GLOBALS

$GLOBALS a Super global variable array can be considered a superset of a super global variable that contains all the variables within the global scope. Execute the following code to view all the variables in the $globals.

Copy Code code as follows:

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.