gethostbyname() when host not found

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 11
Joined: Fri Jan 28, 2011 7:21 pm

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>");

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

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?

Post Reply