Home > php教程 > php手册 > PHP $_SERVER[

PHP $_SERVER[

WBOY
Release: 2016-05-25 16:45:32
Original
1241 people have browsed it

有说相同的,有说不同的,都没说明原因,没经过验证就互相转来转去的,浪费观众时间,下面说说本人经过亲自验证 + 查阅官方文档 + 官方BUG列表 + 官方邮件列表 + sitepoint + webmasterworld + google的总结:

相同点:

当满足以下三个条件时,两者会输出相同信息.

1. 服务器为80端口

2. apache的conf中ServerName设置正确

3. HTTP/1.1协议规范

不同点:

1. 通常情况:_SERVER["HTTP_HOST"] 在HTTP/1.1协议规范下,会根据客户端的HTTP请求输出信息.

_SERVER["SERVER_NAME"] 默认情况下直接输出apache的配置文件httpd.conf中的ServerName值.

2. 当服务器为非80端口时:_SERVER["HTTP_HOST"] 会输出端口号,例如:phprm.com:8080

_SERVER["SERVER_NAME"] 会直接输出ServerName值,因此在这种情况下,可以理解为,HTTP_HOST = SERVER_NAME:SERVER_PORT

3. 当配置文件httpd.conf中的ServerName与HTTP/1.0请求的域名不一致时:

httpd.conf配置如下:

<virtualhost *> 
ServerName phprm.com 
ServerAlias www.phprm.com 
</virtualhost>
Copy after login

客户端访问域名www.phpfensi

_SERVER["HTTP_HOST"] 输出 www.phprm.com

_SERVER["SERVER_NAME"] 输出 phprm.com

所以,在实际程序中,应尽量使用_SERVER["HTTP_HOST"],比较保险和可靠.

文章链接:

随便收藏,请保留本文地址!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template