[BlueOnyx:23782] Re: Host Name Lookups

Dick Dolby dickdolby at gmail.com
Mon Mar 30 13:23:03 -05 2020


Hi Michael,

Yes you're correct about $_SERVER['REMOTE_HOST'], but the issue is that
because lookups are disabled, this comes back blank.

I'll give that gethostbyaddre() a try - it sounds like it'll work.

Thanks for your input.


DD


On Mon, Mar 30, 2020 at 5:49 PM Michael Stauber <mstauber at blueonyx.it>
wrote:

> 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
> _______________________________________________
> Blueonyx mailing list
> Blueonyx at mail.blueonyx.it
> http://mail.blueonyx.it/mailman/listinfo/blueonyx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.blueonyx.it/pipermail/blueonyx/attachments/20200330/865c0a3e/attachment.html>


More information about the Blueonyx mailing list