PHP Learning 1.5-Predefined Hyper-global array variables

Source: Internet
Author: User
Tags http cookie http file upload http post php server

1.PHP pre-defined array of hyper-global variables

Characteristics:

A. Special array, no difference in operation mode

B. Without a declaration, the PHP script exists by default because it is not defined in PHP, so the custom variable should be avoided with the same name as the predetermined global variable

C. Automatically in the global scope, that is, can be used directly in the function, without using the Global keyword access

2. Array of hyper-global variables

A.$_server Server Variables

$_server is an array containing information such as header, path, and location of the script

Example:

foreach ($_server as $key = = $value) {
Echo ' $_server[' +. $key + ']= '. $value. ' <br> ';

}

B.$_ENV Environment variables

The contents of the $_env array are converted from environment variables in PHP server to PHP global variables when PHP parser is running.

Example:

foreach ($_env as $key = = $value) {
Echo ' $_env[' +. $key + '] '. $value. ' <br> ';

}

C.$_get URL GET Variable

The $_get array is also a hyper-global variable array, which is an array of variables passed by the URL GET method, which is an external variable, that is, in the server page by $_get the Hyper Global array URL or form GET mode

Passed over the parameters

Example:

Http://www.xxx.com/index.php?id=1&name=lin

Echo ' id= '. $_get[' Id ']. ' <br> ';

Echo ' name= '. $_get[' Name ']. ' <br> ';

Or: Print_r ($_get);

D.$_post HTTP POST variables
The $_post array is a variable that is passed by the HTTP POST method into an array of $_post and $_get arrays that can hold the form's submitted variables
Example:
<form action= ' save.php ' method= ' post ' >
<input type= ' text ' name= ' name '/>
<input type= ' text ' name= ' id '/>
</form>
foreach ($_post as $key = = $value) {
echo $key. ' = ' $value. ' <br> ';
}

E.$_request REQUEST Variable
This associative array contains all the contents of $_get $_post and $_cookie if the form is submitted via the POST of form, it is obtained through $_post.
Get mode is sent in $_get way. $_request no concern is post or get, that is, $_request can get get or post data but
Slow speed.


F.$_files HTTP File Upload variables
When uploading a file using the form file input field, it must be submitted using post but not on the server side via the $_post file but through $_files.
$_files is a two-dimensional array that contains 5 of child elements.


G.$_cookie HTTP Cookies
$_cookie Hyper-global arrays are submitted to script variables via the HTTP cookie method, through which the previously executed PHP script is passed through Setcookie ()
The function is set to the client's browser, and the PHP script automatically converts the COOKIE from the client to a variable, which can be $_cookie by a hyper-global array and
The name of the cookie to access the specified cookies value.


H.$_session SESSION Variable
Session control is used to track users on the server using the session, and when the session is opened using the Session_Start () function in the server page, you can use the $_session
The array host global variable.


I. $GLOBALS Global
$GLOBALS is an array of global variables defined so that the variable name is the index of the array and is valid in all scripts, not in the method in the function or object.
You need to use the keyword global access to declare global variables outside the function, and you can use the $_globals array instead of the global keyword
Example:
$a =1; $b = 2;

function $sum () {

$GLOBALS [' B ']= $GLOBALS [' A ']+ $GLOBALS [' B '];
}
$sum ();
Echo $b;

PHP Learning 1.5-Predefined Hyper-global array variables

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.