[BlueOnyx:23781] Re: Host Name Lookups

Michael Stauber mstauber at blueonyx.it
Mon Mar 30 11:42:34 -05 2020


Hi Dick,

> however I actually just want a single site’s PHP to be able to resolve IP addresses to a more human-readable form. 

I may not understand the problem at hand correctly, but PHP can easily
tell you not only the IP of the connection, but also the hostname as
reported by DNS.

Sure "Host Name Lookups" must be enabled in Apache in order for the PHP
environment variable 'REMOTE_HOST' to be set.

But 'REMOTE_ADDR' is set anyway, so you have the IP. So you can just do
an extra step like this ...

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

... and you get the hostname.

But as always the devil is in the details. You might want to configure
DNS timeouts, if the visitor uses a web proxy you might need to use
$_SERVER['HTTP_X_FORWARDED_FOR'] instead of $_SERVER['REMOTE_ADDR'] and
you need error checks for the cases where that routine chokes because
$_SERVER['REMOTE_ADDR'] reported more than one IP.

-- 
With best regards

Michael Stauber



More information about the Blueonyx mailing list