陣列元素 | 說明 |
---|---|
$_SERVER['PHP_SELF'] | 當前執行指令碼的檔名,與 document root 有關。例如,在地址為 http://c.biancheng.net/test.php/foo.bar 的指令碼中使用 $_SERVER['PHP_SELF'] 將得到 /test.php/foo.bar |
$_SERVER['SERVER_ADDR'] | 當前執行指令碼所在伺服器的 IP 地址 |
$_SERVER['SERVER_NAME'] | 當前執行指令碼所在伺服器的主機名。如果指令碼執行於虛擬主機中,該名稱就由那個虛擬主機所設定的值決定 |
$_SERVER['SERVER_PROTOCOL'] | 請求頁面時通訊協定的名稱和版本。例如,“HTTP/1.0” |
$_SERVER['REQUEST_METHOD'] | 存取頁面使用的請求方法。例如“GET”“HEAD”“POST”“PUT” |
$_SERVER['DOCUMENT_ROOT'] | 當前執行指令碼所在的文件根目錄。在伺服器組態檔中定義 |
$_SERVER['HTTP_ACCEPT_LANGUAGE'] | 當前請求頭中 Accept-Language: 項的內容(如果存在)。例如,“en” |
$_SERVER['REMOVE_ADDR'] | 瀏覽當前頁面的使用者 IP 地址,注意與 $_SERVER['SERVER_ADDR'] 的區別 |
$_SERVER['SCRIPT_FILENAME'] | 當前執行指令碼的絕對路徑 |
$_SERVER['SCRIPT_NAME'] | 包含當前指令碼的路徑 |
$_SERVER['REQUEST_URI'] | URI 用來指定要存取的頁面。例如,“index.html” |
$_SERVER['PATH_INFO'] | 包含由用戶端提供的、跟在真實指令碼名稱之後並且在查詢語句(query string)之前的路徑資訊(如果存在)。例如,當前指令碼是通過 URL http://c.biancheng.net/php/path_info.php/some/stuff?foo=bar 被存取的,那麼 $_SERVER['PATH_INFO'] 將包含 /some/stuff |
<?php print_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] => [email protected]
[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
)