Skip to content
Advertisement

Message: Undefined index: REMOTE_HOST in $_SERVER

Why do I get this error when I try to retrieve host name of remote user ?

Message: Undefined index: REMOTE_HOST

When reading documentation I came to know that it needs to be enabled in httpd.conf. But I am not sure what needs to be edited in httpd.conf.

Advertisement

Answer

This is not an error, it’s a notice. REMOTE_HOST is not defined in all cases. REMOTE_ADDR is. You need to reconfigure your webserver if you need it. HostnameLookups On does it, but it incurs a slowdown.

Alternative: Let PHP do the lookup, so you can skip it (for speed) when not needed:

$r = $_SERVER["REMOTE_HOST"] ?: gethostbyaddr($_SERVER["REMOTE_ADDR"]);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement