1. overview PHP environment variables include: $ GLOBALS []: stores all global variables in the current script. The KEY is the variable name, and the VALUE is the variable $ _ SERVER []: current WEB server variable array $ _ GET []: stores the data in the form submitted using the GET method $ _ POST []: stores the data in the form submitted using the POST method $ _ COOKIE []: obtain or set a User Token
1. overview PHP environment variables include: $ GLOBALS []: stores all global variables in the current script. The KEY is the variable name, and the VALUE is the variable $ _ SERVER []: current WEB server variable array $ _ GET []: stores the data in the form submitted using the GET method $ _ POST []: stores the data in the form submitted using the POST method $ _ COOKIE []: obtain or set a User Token
1. Overview
PHP environment variables mainly include:
$ GLOBALS []: stores all global variables in the current script. The KEY is the variable name, and the VALUE is the variable VALUE.
$ _ SERVER []: array of current web server Variables
$ _ GET []: stores the data in the form submitted using the GET method.
$ _ POST []: stores data in the form submitted using the POST method
$ _ COOKIE []: Get or set the array of variables stored in Cookies in the user's browser
$ _ FILES []: stores the data submitted to the current script by the uploaded file.
$ _ ENV []: stores the current WEB environment variable
$ _ REQUEST []: stores all REQUEST arrays in the submission form, including $ _ GET, $ _ POST, $ _ COOKIE, and $ _ SESSION.
$ _ SESSION []: an array of SESSION variables for storing the current script
2. $ GLOBALS []
GLOBALS is an array composed of defined global variables. The variable name is the index of the array. For example:
$ENTER = "
";$var1 = 5; $var2 = 10; print $GLOBALS['var1'] . $ENTER ;print $GLOBALS['var2'] . $ENTER ;
GLOBALS and global are similar, but there are some differences, refer to: http://www.neatstudio.com/show-644-1.shtml
3. $ _ SERVER []
_ SERVER is an array containing information such as header, path, and script locations. For example:
$ENTER = "
";print "SERVER_ADDR:" . $_SERVER['SERVER_ADDR'] . $ENTER;
Reference: http://www.php.net/manual/zh/reserved.variables.server.php
4. $ _ GET and _ POST
$ _ GET and _ POST are used to receive request data and implement Input
$ _ GET content is transmitted to the array of variables of the current script through URL parameters.
$ _ POST is the variable name and value sent by the http post method.
GET is the most primitive Request Method in HTTP. a GET request is sent when you click a hyperlink in a webpage or enter a URL in the address bar. In a GET request, the data is sent after the URL suffix, like: http: // 192.168.21.20./ test1.php? Name_get = zxm & age_get = 23
The main purpose of the POST method is to pass data. It uploads the data after all request headers, so that no matter how much data is uploaded.
Eg:
HTML:
Php:
//_GETecho "name:" . $_GET["name_get"] . $ENTER ;echo "age:" . $_GET["age_get"] . $ENTER;//_POSTecho "name:" . $_POST["name_post"] . $ENTER ;echo "age:" . $_POST["age_post"] . $ENTER;?>
5. $ _ FILE
With $ _ FILES, we can upload FILES from the client's computer to a remote server.
Upload File Form:
PHP:
//_FILEecho "Error: " . $_FILES["file"]["error"] . "
";echo "Upload: " . $_FILES["file"]["name"] . "
";echo "Type: " . $_FILES["file"]["type"] . "
";echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";echo "Stored in: " . $_FILES["file"]["tmp_name"];
6. _ COOKIE []
Cookie is a mechanism for storing data in a remote browser to track and identify users. It is often used to identify users. When the same computer requests a page through a browser, it also sends a cookie. Through $ _ COOKIE [], we can retrieve the cookie.
Set cookie:
Read cookie:
//cookieif (isset($_COOKIE['user'])) echo "Welcome " . $_COOKIE['user'] . "!
";else echo "Welcome guest!
";
7. _ SESSION []
_ SESSION [] stores information about user sessions.
Eg:
Php:
//sessionif(isset($_SESSION['id'])) echo "session id: " . $_SESSION['id'] . $ENTER;else echo "without session" . $ENTER;?>
7. _ ENV []
In php, $ _ ENV stores some system environment variables, which have different values due to different environments.
8. _ REQUEST []
$ _ REQUEST contains all the content of $ _ GET, $ _ POST, and $ _ COOKIE.
$ _ GET, $ _ POST, and $ _ COOKIE all have a copy in $ _ REQUEST. Changing the value of $ _ REQUEST does not affect $ _ GET, and vice versa.
Priority: $ _ GET <$ _ POST <$ _ COOKIE
EG:
//requestecho "request: " . $_REQUEST['name_get'] . "!
";?>
8. Test the PHP program:
";//__GLOBALS[]$var1 = 5; $var2 = 10; print $GLOBALS['var1'] . $ENTER ;print $GLOBALS['var2'] . $ENTER ;//_SERVERprint "SERVER_ADDR:" . $_SERVER['SERVER_ADDR'] . $ENTER;//_GETecho "name:" . $_GET["name_get"] . $ENTER ;echo "age:" . $_GET["age_get"] . $ENTER;//_POSTecho "name:" . $_POST["name_post"] . $ENTER ;echo "age:" . $_POST["age_post"] . $ENTER;//_FILEecho "Error: " . $_FILES["file"]["error"] . $ENTER;echo "Upload: " . $_FILES["file"]["name"] . $ENTER;echo "Type: " . $_FILES["file"]["type"] . $ENTER;echo "Size: " . ($_FILES["file"]["size"] / 1024) . $ENTER;echo "Stored in: " . $_FILES["file"]["tmp_name"] . $ENTER;//cookieif (isset($_COOKIE['user']))echo "Welcome: " . $_COOKIE['user'] . "!
";elseecho "Welcome guest!
";//sessionif(isset($_SESSION['id']))echo "session id: " . $_SESSION['id'] . $ENTER;elseecho "without session" . $ENTER;//requestecho "request: " . $_REQUEST['name_get'] . "!
";?>