开发者

Retrieve Domain Name instead of IP

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.


gethostbyaddr() can retrieve a hostname for the IP address, but only if DNS record has been set up properly


useful link: http://php.net/manual/en/reserved.variables.server.php use $_SERVER["SERVER_NAME"]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜