Home > Backend Development > PHP Tutorial > host是否带port的问题讨论

host是否带port的问题讨论

WBOY
Release: 2016-06-23 14:13:22
Original
2117 people have browsed it

$_SERVER['HTTP_HOST'] 得到的host是带端口号的,理论上讲host为主机名,不应该带端口号。


回复讨论(解决方案)

$_SERVER['HTTP_HOST'] 不会带有端口号
$_SERVER['SERVER_PORT'] 才是端口号

$_SERVER['HTTP_HOST'] 不会带有端口号
$_SERVER['SERVER_PORT'] 才是端口号
亲测,非80端口时,$_SERVER['HTTP_HOST']是带有端口号的。

那你好好研究下php的全局变量$_server吧。
参考链接:
php URL各部分获取方法(全局变量)
http://www.jbxue.com/article/6798.html

$_SERVER['HTTP_HOST'] 会带有,因为是http中request头部信息的Host头域 。

Host头域 

Host头域指定请求资源的Intenet主机和端口号,必须表示请求url的原始服务器或网关的位置。HTTP/1.1请求必须包含主机头域,否则系统会以400状态码返回。 


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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template