Home > Backend Development > PHP Tutorial > Superglobal array (predefined variables)

Superglobal array (predefined variables)

WBOY
Release: 2016-07-29 09:06:33
Original
1095 people have browsed it

Server variables: $_SERVER
Environment variables: $_ENV
HTTP GET variables: $_GET
HTTP POST variable: $_POST
request variable: $_REQUEST
HTTP file upload variable: $_FILES
HTTP Cookies: $_COOKIE
Session variable: $_SESSION
Global variable: $_GLOBALS

Server variables: $_SERVER

$_SERVER is an array containing information such as header, path and script locations. The entities of the array are created by the web server. There is no guarantee that all servers will produce all messages; servers may ignore some messages or generate new messages not listed below. This is an automatic global variable. This just means that it works in all scripts. There is no need to use global $_SERVER in functions or methods;
PHP_SELF: The file name of the currently executing script
DOCUMENT_ROOT: The document root directory where the currently running script is located
REMOTE_ADDR: The IP address of the user who is browsing the current page.

<?php
	echo count($_SERVER);
	foreach($_SERVER as $key=>$value)
		echo "{$key}=>{$value}<br>";
Copy after login

Output:

33HTTP_HOST=>localhost
HTTP_C/span>
HTTP_ACCEPT=>text/html,application/xhtml+xml,application/xml;q=0.9,image/ webp,*/*;q=0.8
HTTP_USER_AGENT=>Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
HTTP_ACCEPT_ENCOD ING=> gzip,deflate,sdch
HTTP_ACCEPT_LANGUAGE=>zh-CN,zh;q=0.8
PATH=>C:ProgramDataOracleJavajavapath;C:Program Files (x86)InteliCLS Client;C:Program FilesInteliCLS Client;C: Program Files (x86)NVIDIA CorporationPhysXCommon;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C :Program FilesLenovoBluetooth Software;C:Program FilesLenovoBluetooth Softwaresyswow64;C:Program Files (x86)LenovoLenovo Home;%JAVA_HOME%bin;%JAVA_HOME%jrebin;C:Program Files (x86)Windows Kits8.1Windows Performance Toolkit;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program FilesMySQLMySQL Server 5.5bin;
SystemRoot=>C:WINDOWS
COMSPEC=>C:WINDOWSsystem32cmd.exe
PATHEXT=>.COM;.EXE;.BAT;. CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
WINDIR=>C:WINDOWS
SERVER_SIGNATURE=>
Apache/2.4.9 (Win32) PHP /5.5.12 Server at localhost Port 80
SERVER_SOFTWARE=>Apache/2.4.9 (Win32) PHP/5.5.12
SERVER_NAME=>localhost
SERVER_ADDR=>::1
SERVER_PORT=>80
REMOTE_ADDR=>::1
DOCUMENT_ROOT=>C:/wamp/www/
REQUEST_SCHEME=>http
C/span>
C/ wamp/ www/
SERVER_ADMIN=>admin@example.com
SCRIPT_FILENAME=>C:/wamp/www/array/arr1.php
REMOTE_PORT=>21721
GATEWAY_INTERFACE=&g t;CGI/ 1.1
SERVER_PROTOCOL=>HTTP/1.1
REQUEST_METHOD=>GET
QUERY_STRING=>
REQUEST_URI=>/array/arr1.php
SCRIPT_NAME=>/array/arr1 .php
PHP_SELF=>/array/arr1.php
REQUEST_TIME_FLOAT=>1452865977.555
REQUEST_TIME=>1452865977

Environment variable: $_ENV

Parsing When the server is running, these variables are converted from environment variables into the PHP global variable namespace (namespace). Many of them are determined by the system PHP is running on. A complete list is impossible. Check your system's documentation to determine its specific environment variables.
This is an automatic global variable. It works in all scripts. There is no need to use global $_ENV in functions or methods;

The above has introduced superglobal arrays (predefined variables), including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template