HTTP_HOST 和 SERVER_NAME 的区别

PHP的SERVER保留变量中 HTTP_HOSTSERVER_NAME 经常是一样的,原因是服务器端口是80,那么HTTP_HOST将省略不显示,而HTTP服务的默认端口就是80,所以大多数情况下,HTTP_HOST都没有显示这个端口号。而如果使用的是ssl链接,那么端口号将被显示出来。

所以HTTP_HOST = SERVER_NAME:SERVER_PORT

访问请求:
12.62.201.12:8013/test.php

打印$_SERVER

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] => [email protected]
    [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
)

你可能感兴趣的:(php)