tags:

views:

168

answers:

4

How can I resolve an IP address to a hostname using PHP?

+2  A: 

gethostbyaddr()

Øystein Riiser Gundersen
+6  A: 

You can use the gethostbyaddr() function.

$hostname = gethostbyaddr($ipAddress);
Greg
A: 

You should give gethostbyaddr() a shot.

KB22
+2  A: 

Use gethostbyaddr()

$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);

echo $hostname;

You might find that this function can hang for some time when an address is not found - if this becomes a performance issue for you, check this manual comment which details a hand-coded method which supports a timeout.

Paul Dixon