[英]Get domain name without port using HTTP_HOST
When I check the logs there are a few rare occasions where for some visitors(bot I think) the $_SERVER['HTTP_HOST']
is returning: www.domain.co.uk:80 当我检查日志时,有一些罕见的情况,对于一些访问者(我认为是机器人) $_SERVER['HTTP_HOST']
正在返回:www.domain.co.uk:80
What is the correct way to get only the domain name without any ports? 只获取没有任何端口的域名的正确方法是什么?
Should I be doing it this way instead: 我应该这样做吗:
$url_components = parse_url($_SERVER['HTTP_HOST']);
$domain = $url_components['host'];
The strange thing is that I cant replicate this behavior it only appears in the logs. 奇怪的是,我无法复制这种只出现在日志中的行为。
在这种情况下, $_SERVER['SERVER_NAME']
是您的朋友。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.