Home  >  Article  >  Backend Development  >  php如何靠谱的获取当前域名?

php如何靠谱的获取当前域名?

WBOY
WBOYOriginal
2016-06-06 20:35:59898browse

$_SERVER['HTTP_HOST'] 经常将域名转换为IP,我也是URL访问的,求解决

回复内容:

$_SERVER['HTTP_HOST'] 经常将域名转换为IP,我也是URL访问的,求解决

可参考Symfony的HttpFoundation组件里Request类上获取host的方法:

https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Http...

需要判断是不是反向代理的请求(从请求头里查),否则从HOST头或$_SERVER变量里取。

Statement:
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