Home  >  Article  >  Backend Development  >  Overview of PHP predefined variable array types_PHP tutorial

Overview of PHP predefined variable array types_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:33:15999browse

PHP predefined variable array 1, $_SERVER

$_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 number of variables in $_SERVER will be different, but generally you can find the variables defined in the CGI1.1 specification. These include:

$_SERVER[ 'HTTP_REFERER' ] ; URL of the page that leads the user to the current location;

$_SERVER[ 'REMOTE_ADDR' ] ; Customer IP address;

$_SERVER[ 'REQUEST_URI' ] ; The path part 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 browser.

PHP predefined variable array 2. $_GET

$_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, to access variables passed through the GET method, $_GET Super global variables are the only way.

PHP predefined variable array 3. $_POST

$_POST super global variable contains information about parameters passed by the POST method.

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> </span><span class="tag-name">form</span><span> </span><span class="attribute">caction</span><span>=</span><span class="attribute-value">"subscribe.php"</span><span> </span></span></li><li class="alt"><span><span class="attribute">method</span><span> = </span><span class="attribute-value">"post"</span><span class="tag">></span><span> </span></span></li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">p</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span>Email address : </span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"email"</span><span> </span></li><li><span class="attribute">size</span><span>=</span><span class="attribute-value">"20"</span><span> </span><span class="attribute">maxlength</span><span>=</span><span class="attribute-value">"so"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">""</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> /p</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">p</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span>Password : </span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"password"</span><span> </span></li><li><span class="attribute">name</span><span>=</span><span class="attribute-value">"pswd"</span><span> </span><span class="attribute">size</span><span>=</span><span class="attribute-value">"20"</span><span> </span><span class="attribute">maxlength</span><span>=</span><span class="attribute-value">"15"</span><span> </span></li><li><span class="attribute">value</span><span>=</span><span class="attribute-value">""</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> /p</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> </span><span class="tag-name">p</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> </span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"submit"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"subscribe"</span><span> </span></li><li class="alt"><span class="attribute">value</span><span>=</span><span class="attribute-value">"subscribe!"</span><span class="tag">></span><span> </span>
</li>
<li>
<span class="tag"><</span><span> /p</span><span class="tag">></span><span> </span>
</li>
<li class="alt">
<span class="tag"><</span><span> /form</span><span class="tag">></span><span> </span>
</li>
</ol>

Through the script subscribe.php, you can use the following POST variable:

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

$_POST[ 'pswd' ] = "rainyday" ;

$_POST[ 'subscribe' ] = "subscribe!" ;

Like $_GET, by default the $_POST superglobal variable is the only way to access POST variables.

PHP predefined variable array 4, $_COOKIE

$_COOKIE super global variable stores the information passed to the script through HTTP cookie. These cookies are generally set by a previously executed PHP script through the PHP function setcookie(). For example, suppose you use setcookie() to store a cookie named example.com with a value of ab2213. This value can be obtained later by calling $_COOKIE['example.com'].

PHP predefined variable array 5, $_FILES

$_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 file upload element name of the form; the second subscript is one of five predefined subscripts that describe a certain attribute of the uploaded file:

$_FILES[ ' upload-name' ][ 'name' ]; The file name of the file uploaded from the client to the server;

$_FILES[ 'upload-name' ][ 'type' ]; The MIME type of the uploaded file, this Whether a variable is assigned a value depends on the browser's capabilities.

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

$_FILES[ 'upload-name' ][ ' tmp_name' ]; The temporary name given to this file before it is moved to its final location after uploading.

$_FILES[ 'upload-name' ][ 'error' ]; Upload status code. Although this variable is named error , this variable is actually filled in on success. It has five possible values:

UPLOAD_ERR_OK File uploaded successfully

UPLOAD_ERR_INI_SIZE The file size exceeded the maximum value specified by the upload_max_filesize directive.

UPLOAD_ERR_FORM_SIZE The file size exceeds the maximum value specified by the MAX_FILE_SIZE hidden form field parameter (optional).

UPLOAD_ERR_PARTIAL Only part of the file was uploaded

UPLOAD_ERR_NO_FILE No file specified in the upload form

PHP predefined variable array 6, $_ENV

$_ENV super global variable provides information about the server environment where PHP parses. Variables in this array include:

$_ENV[ 'HOSTNAME' ] Server's host name

$_ENV[ 'SHELL' ] System shell

PHP predefined variable array 7, $_REQUEST

$_REQUEST super global variable is an all-rounder, which records the variables passed to the script through various methods, 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 on the order specified by the variables_order configuration directive. It is recommended to use this super variable sparingly because it is not safe enough.

PHP predefined variable array 8. $_SESSION

$_SESSION super global variable contains information related to all sessions. Registering session information gives you the convenience of being able to reference it throughout your site without having to explicitly pass the data via GET or POST.

PHP predefined variable array 9. $GLOBALS

$GLOBALS The super global variable array can be considered a superset of super global variables, including All variables in the global scope. Execute the following code to view all variables in $GLOBALS.

<ol class="dp-xml">
<li class="alt"><span><span>print ' </span><span class="tag"><</span><span class="tag-name">pre</span><span class="tag">></span><span>' ;  </span></span></li>
<li><span>print_r ($GLOBALS);  </span></li>
<li class="alt">
<span>print ' </span><span class="tag"></</span><span class="tag-name">pre</span><span class="tag">></span><span>' ; </span>
</li>
</ol>



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446080.htmlTechArticlePHP predefined variable array 1. $_SERVER The $_SERVER super global variable contains information created by the web server, which provides Provides information about server and client configurations and the current request environment. According to...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn