PHP的SERVER保留變量中 HTTP_HOST
和 SERVER_NAME
常常是同樣的,緣由是服務器端口是80,那麼HTTP_HOST將省略不顯示,而HTTP服務的默認端口就是80,因此大多數狀況下,HTTP_HOST都沒有顯示這個端口號。而若是使用的是ssl連接,那麼端口號將被顯示出來。php
因此HTTP_HOST = SERVER_NAME:SERVER_PORT
html
訪問請求:
12.62.201.12:8013/test.phpweb
打印$_SERVERapache
print_r($_SERVER);
Array ( [HTTP_HOST] => 12.62.201.12:8013 [HTTP_CONNECTION] => keep-alive [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 [HTTP_REFERER] => http://58.62.201.107:8091/ [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_COOKIE] => PHPSESSID=4v3njmj1bot72q66kpo3mcam42 [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/php/bin:/usr/local/apache/bin:/root/bin [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.2.31 (Unix) PHP/5.5.36 [SERVER_NAME] => 12.62.201.12 [SERVER_ADDR] => 192.168.17.120 [SERVER_PORT] => 8013 [REMOTE_ADDR] => 2.2.2.2 [DOCUMENT_ROOT] => /usr/local/apache/htdocs [SERVER_ADMIN] => you@example.com [SCRIPT_FILENAME] => /usr/local/apache/htdocs/test.php [REMOTE_PORT] => 2104 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /test.php [SCRIPT_NAME] => /test.php [PHP_SELF] => /test.php [REQUEST_TIME_FLOAT] => 1501652634.963 [REQUEST_TIME] => 1501652634 )