This has nothing to do with reliability. Both variables simply do not match, although under certain circumstances they may contain the same value. Let me explain:
$_SERVER['REMOTE_ADDR']
in all cases will contain the IP address of the remote host, where
$_SERVER['REMOTE_HOST']
will contain the DNS host name if DNS resolution is enabled (if the HostnameLookups Apache directive is set to On , thanks @Pekka). If it is disabled, then $_SERVER['REMOTE_HOST'] will contain the IP address, and this is what you might notice.
Your code should look like this:
$host = $_SERVER['REMOTE_HOST']; // if both are the same, HostnameLookups seems to be disabled. if($host === $_SERVER['REMOTE_ADDR']) { // get the host name per dns call $host = gethostbyaddr($_SERVER['REMOTE_ADDR']) }
Note. If you can manage the apache directive, I would advise you to disable it for performance reasons and get the host name - only if you need it - using gethostbyaddr()
source share