note 17829 deleted from function.gethostbyname by jimw
| From: | jimw@php.net | Date: | Wed, 02 Jan 2002 11:03:41 +0000 |
| Subject: | note 17829 deleted from function.gethostbyname by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24205@lists.php.net to get a copy of this message | ||
gethostbyaddress( "server.com" ) sometimes returns "server.com", which means a
valid IP-address could not be found. This can be resolved by checking www.server.com:
$url = "server.com";
$serverip = gethostbyname( $url );
if( $url == $serverip && !is_numeric( str_replace( ".", "", $serverip )
) )
{
$serverip = gethostbyname( "www.". $url );
}
if( !is_numeric( str_replace( ".", "", $serverip ) ) )
echo "couldn't resolve";
else
echo $serverip;
Checking to see if the address returned is not an IP-address is important. Getting the address of an
IP address will always return an IP address