Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

gethostbyname() when host not found

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

gethostbyname() when host not found

Postby DaveKimble » Sat Apr 20, 2013 8:00 pm

I look after 4 websites, 2 of which are hosted on different remote machines, 2 on a server on my LAN, and 2 mirrors also on the local server. I have been adjusting the name server setting, and have written a PHP script that uses the function gethostbyname() so that I can see when the propagation of the changes has occurred on the remote servers.

The PHP manual says when a hostname is not found, the function returns the input parameter, (not FALSE). The script runs correctly on the remote servers, but on the local server it is returning the IP of OpenDNS. It is a trivial problem, but I want to get to the bottom of it.

Code: Select all
function gethostip($host)
{   $hostip = gethostbyname($host);
   if ($hostip == $host) { $hostip = "no record"; }
   echo ("<TR><TD>".$host."</TD><TD>".$hostip."</TD></TR>");
New php-forum User
New php-forum User
Posts: 11
Joined: Fri Jan 28, 2011 7:21 pm

Re: gethostbyname() when host not found

Postby johnj » Sat Apr 20, 2013 10:45 pm

1).What does gethostbyname("localhost") return in your case?
2).In your code, please print $host on local server. what does it display?
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.