简体   繁体   中英

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

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']是您的朋友。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM