Search code examples
phpgethostbyname

PHP gethostbyname returns hostname instead of IP address


I am checking current hosting IP of websites using

$ip = gethostbyname('domainname.com');

It Returns IP address of websites working well but for some domains it returns back the domain name

$ip = gethostbyname('domainname.com');

Returns:

domianname.com


Solution

  • As mentioned in the documentation:

    Returns the IPv4 address or a string containing the unmodified hostname on failure.

    So you are on a failure situation.