The differences between HTTP_HOST and SERVER_NAME in PHP are similar:
When the following three conditions are met, the two will output the same information.
1. the server is port 80.
2. set ServerName correctly in apache conf.
3. HTTP/1.1 Protocol specification
Differences:
1. general situation:
_ SERVER ["HTTP_HOST"] under the HTTP/1.1 protocol specification, information is output according to the client's HTTP request.
_ SERVER ["SERVER_NAME"] by default, the ServerName value in the configuration file httpd. conf of apache is directly output.
2. when the server is not port 80:
_ SERVER ["HTTP_HOST"] outputs the port number, for example, mimiz.cn: 8080.
_ SERVER ["SERVER_NAME"] directly outputs the ServerName value
Therefore, it can be understood as: HTTP_HOST = SERVER_NAME: SERVER_PORT
3. when the ServerName in the configuration file httpd. conf is inconsistent with the domain name of the HTTP/1.0 request:
Httpd. conf is configured as follows:
ServerName mimiz.cn
ServerAlias www.mimiz.cn
Client Access domain name www.mimiz.cn
_ SERVER ["HTTP_HOST"] outputs www.mimiz.cn
_ SERVER ["SERVER_NAME"] outputs mimiz.cn
Therefore, in actual programs, _ SERVER ["HTTP_HOST"] should be used as much as possible, which is relatively safe and reliable.