PHP $_SERVER
By Vincent. @2021.1.15
$_SERVER 是 PHP 预定义变量之一,可以直接使用,它是一个包含了诸如头信息(header)、路径(path)及脚本位置(script locations)信息的数组。
在浏览器打印出 $_SERVER 数组的代码如下:
<?phpprint_r($_SERVER);?>
浏览器的输出结果如下:
Array
(
[HTTP_HOST] => localhost
[HTTP_CONNECTION] => keep-alive
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9, image/webp,*/*;q=0.8
[HTTP_UPGRADE_INSECURE_REQUESTS] => 1
[HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36
[HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch
[HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8
[HTTP_COOKIE] => PHPSESSID=e1bbc84e23bf85691e7c5a4ab07ee0de; pgv_pvi=4369311744; pgv_si=s1775918080; CNZZDATA155540=cnzz_eid%3D1811041545- 1463297631-%26ntime%3D1463303031
[PATH] => /usr/bin:/bin:/usr/sbin:/sbin
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache/2.4.16 (Unix) PHP/7.0.5
[SERVER_NAME] => localhost
[SERVER_ADDR] => ::1
[SERVER_PORT] => 80
[REMOTE_ADDR] => ::1
[DOCUMENT_ROOT] => /Library/WebServer/Documents
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /Library/WebServer/Documents
[SERVER_ADMIN] => you@example.com
[SCRIPT_FILENAME] => /Library/WebServer/Documents/book/str.php
[REMOTE_PORT] => 59377
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /book/str.php
[SCRIPT_NAME] => /book/str.php
[PHP_SELF] => /book/str.php
[REQUEST_TIME_FLOAT] => 1463828978.149
[REQUEST_TIME] => 1463828978
[argv] => Array
(
)
[argc] => 0
)