All,
I am using the following command to retrieve the domain name of my server.
$_SERVER['HTTP_HOST']
This seems to return the IP address instead of domain name like www.example.com. I looked at PHPInfo and it also lists an IP address for HTTP_HOST instead of Domain name. What do I need to change to make the domain name appear instead of IP?
Thanks
Use $_SERVER['SERVER_NAME']
instead.
Or, you can look at every Server Variable you have available but putting this script in one of your PHP pages on this server.
<?PHP
foreach($_SERVER as $key_name => $key_value) {
print $key_name . " = " . $key_value . "<br>";
}
?>
$_SERVER['HTTP_HOST']
(which may not be defined if the client made a HTTP/1.0 request) contains the hostname that the client requested.
If the client requested http://127.0.0.1/
it would contain 127.0.0.1
; for http://localhost/
it would contain localhost
; for http://127.0.0.1:81/
it would contain 127.0.0.1:81
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With