Dharani Dharan
Dharani Dharan

Reputation: 644

gethostbyname function returns domain name instead of IP address in PHP

I want to get machine IP address in PHP so i am using function

<?php echo gethostbyname($serverName); ?>

Its works for all my server machine but it returns domain name for particular IP address for some machine. I don't know why its returning domain name for particular machine and how to get IP address of that particular machine.

Thanks in advance.

Upvotes: 1

Views: 1045

Answers (1)

Glapa
Glapa

Reputation: 800

According to docs

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

Failure reasons may be couple (e.g. wrong domain name, unreachable host or network problems)

Upvotes: 3

Related Questions