On this issue, search engine found a large article, there are many problems, in this find a correct saying: http://mimiz.cn/index.php/php/php-http_host-server_name-difference/
Reprint a bit
Reference
Recently in the development Station group software, the use of access to the domain name to determine the sub-site related issues. PHP gets the current domain name there are two variables http_host and server_name, I want to know the difference between the two and which is more reliable.
First of all, I would like to say that Baidu on those revolving articles are nonsense!
Have said the same, have said different, did not explain the reason, not verified on each other, wasting the audience time.
Let's say I have personally verified + Check official documents + official Bug list + official mailing list + SitePoint + WebmasterWorld + Google Summary:
Same point:
The same information is output when the following three conditions are met.
1. Server is 80 port
2. ServerName is set correctly in Apache Conf
3. http/1.1 Protocol Specification
Different points:
1. The usual situation:
_server["Http_host"] under the http/1.1 protocol specification, the information is output based on the HTTP request of the client.
_server["SERVER_NAME"] by default, the ServerName value in the Apache configuration file httpd.conf is output directly.
2. When the server is not 80 ports:
_server["Http_host"] outputs the port number, for example: mimiz.cn:8080
_server["SERVER_NAME"] will output servername value directly
So in this case, it can be understood as: Http_host = Server_name:server_port
3. When servername in profile httpd.conf is inconsistent with the domain name requested by http/1.0:
The httpd.conf configuration is as follows:
<virtualhost *>
ServerName mimiz.cn
Serveralias www.mimiz.cn
</virtualhost>
Client Access domain name www.mimiz.cn
_server["Http_host"] Output www.mimiz.cn
_server["SERVER_NAME"] Output mimiz.cn
Therefore, in the actual procedure, should try to use _server["Http_host", more insurance and reliable.
The difference between server_name and http_host in PHP $_server