55

What is the difference between these two variables?

REMOTE_HOST and REMOTE_ADDR.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
hd.
  • 17,596
  • 46
  • 115
  • 165

4 Answers4

50

REMOTE_HOST pertains to the hostname of the client (i.e. the computer making the request). REMOTE_ADDR refers to the IP address of the client.

There would be times when the hostname is unresolvable so the REMOTE_HOST will return the REMOTE_ADDR or the IP address instead.

Nick Zalutskiy
  • 14,952
  • 7
  • 53
  • 50
Ruel
  • 15,438
  • 7
  • 38
  • 49
  • 2
    I want to mention that it's possible to see unexpected results if there are proxy server in the middle. – Dot Freelancer Feb 14 '13 at 17:33
  • 8
    REMOTE_HOST is also only set to the _host_ if `HostnameLookups` is enabled on the server, otherwise it _always_ contains the IP address. (`HostnameLookups` is Off by default - performance reasons.) – MrWhite Jul 14 '14 at 09:00
  • Indeed, REMOTE_HOST can be unresolvable. I saw REMOTE_HOST displayed in phpinfo but when I reloaded the page later, it disappeared. This problem completely broke my phpmyadmin root access and I had to replace "allow root from localhost" with "allow root from ::1" (apache is using IPv6 so 127.0.0.1 will not work). Any ideas why REMOTE_HOST sometimes isn't available? – baptx Sep 24 '14 at 12:06
8

From RFC-3875

  • REMOTE_ADDR:The REMOTE_ADDR variable MUST be set to the network address of the client sending the request to the server.
      REMOTE_ADDR  = hostnumber
      hostnumber   = ipv4-address | ipv6-address
      ipv4-address = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit
      ipv6-address = hexpart [ ":" ipv4-address ]
      hexpart      = hexseq | ( [ hexseq ] "::" [ hexseq ] )
      hexseq       = 1*4hex *( ":" 1*4hex )
  • REMOTE_HOST:The REMOTE_HOST variable contains the fully qualified domain name of the client sending the request to the server, if available, otherwise NULL. Fully qualified domain names take the form as described in section 3.5 of RFC 1034 [17] and section 2.1 of RFC 1123 [12]. Domain names are not case sensitive.
The REMOTE_HOST variable contains the fully qualified domain name of
   the client sending the request to the server, if available, otherwise
   NULL.  Fully qualified domain names take the form as described in
   section 3.5 of RFC 1034 [17] and section 2.1 of RFC 1123 [12].
   Domain names are not case sensitive.

      REMOTE_HOST   = "" | hostname | hostnumber
      hostname      = *( domainlabel "." ) toplabel [ "." ]
      domainlabel   = alphanum [ *alphahypdigit alphanum ]
      toplabel      = alpha [ *alphahypdigit alphanum ]
      alphahypdigit = alphanum | "-"
Community
  • 1
  • 1
NOZUONOHIGH
  • 1,892
  • 1
  • 20
  • 20
4

1. $_SERVER['REMOTE_ADDR'] - This contains the real IP address of the client. That is the most reliable value you can find from the user.

2. $_SERVER['REMOTE_HOST'] - This will fetch the Host name from which the user is viewing the current page. But for this script to work, Hostname Lookups On inside httpd.conf must be configured.

K.Suthagar
  • 2,226
  • 1
  • 16
  • 28
  • Minor point, but `$_SERVER['REMOTE_ADDR']` is the PHP "processed" value as stored in the `$_SERVER` superglobal. The question is specifically referring to the Apache server variables of the same name - these are not necessarily the same value (but should be in this case). eg. `REQUEST_URI` Apache server variable and `$_SERVER['REQUEST_URI']` PHP superglobal can be quite different. – MrWhite Dec 27 '20 at 19:56
1

Remote: is a computer that resides in some distant location from which data retrieved it typically refer to a server in a private network or the public internet.

Remote_ host will return the REMOTE_ ADDR Or the IP address instead .