SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru okrogius's Avatar
    Join Date
    Mar 2002
    Location
    US
    Posts
    622
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_SERVER global vars onvolving IPs

    What's the difference between $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_CLIENT_IP']? I recently noted the second on the phpinfo() funciton and it gives a totally different ip from remote adress var.

  2. #2
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting question. Did some digging. First of all the be all and end all function for detection, from php.net is;

    PHP Code:
    function getip() {
      if (isSet(
    $_SERVER)) {
        if (isSet(
    $_SERVER["HTTP_X_FORWARDED_FOR"])) {
          
    $realip $_SERVER["HTTP_X_FORWARDED_FOR"];
        } elseif (isSet(
    $_SERVER["HTTP_CLIENT_IP"])) {
          
    $realip $_SERVER["HTTP_CLIENT_IP"];
        } else {
          
    $realip $_SERVER["REMOTE_ADDR"];
        }

      } else {
        if ( 
    getenv'HTTP_X_FORWARDED_FOR' ) ) {
          
    $realip getenv'HTTP_X_FORWARDED_FOR' );
        } elseif ( 
    getenv'HTTP_CLIENT_IP' ) ) {
          
    $realip getenv'HTTP_CLIENT_IP' );
        } else {
          
    $realip getenv'REMOTE_ADDR' );
        }
      }
      return 
    $realip;

    My understand was

    REMOTE_ADDR is the simple remote address (will be wrong if proxies are involved).

    HTTP_X_FORWARDED_FOR: the IP addess forwarded by a proxy server, if the visitor is using on

    HTTP_CLIENT_IP: ?

  3. #3
    SitePoint Zealot Klav's Avatar
    Join Date
    Mar 2002
    Location
    Huddersfield, UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's the code that I was looking at on PHP.Net. I'm totally clueless as well. Not even a mention in the actual documentation!

  4. #4
    SitePoint Addict IsaacV's Avatar
    Join Date
    Jan 2002
    Location
    Saint Petersburg
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When a somebody visits your site through a proxy, REMOTE_ADDR will contain the IP of the proxy. So if 100 people visit your site through the proxy, it will look asif one person did 100 visits.

    There is a method that partially solves this problem; HTTP_CLIENT_IP.
    When a proxy is configured to do so, it will send the original user's IP in a header called CLIENT_IP. In PHP this will be made available as a global $HTTP_CLIENT_IP or as a server var: $_SERVER['HTTP_CLIENT_IP'].

    $HTTP_CLIENT_IP contains the IP address of the server that made the request to the proxy (who then relayed the request to your website)

    HTTP_CLIENT_IP is only sent if a proxy is configured to send it so your application should not depend on it and should only use HTTP_CLIENT_IP if it is available.
    Pants.
    Join the NYFlava Fashions Contest

  5. #5
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So are we saying HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP do the same thing?

    Will see if I can so some tests later and come up with the definitive answer, if no one else gets here first.

  6. #6
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK - I've slapped up a script to answer this question once and for all (hopefully).

    Head to http://www.pinkgoblin.com/test/ipcheck.php

    From where I am right now, behind a proxy server that doesn't forward my machines IP address, I only get REMOTE_ADDR which is the address of the proxy server.

    I then tried it using WebGrab on this link;

    http://www.phpcms.de/webgrab/wg.php?...st/ipcheck.php

    This time the REMOTE_ADDR was ns.nmmn.net while both HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP showed the address of the proxy server I'm behind - seems they are the same thing.

    Would be interested to hear what other people get viewing that link.
    Last edited by HarryF; Jun 28, 2002 at 01:39.

  7. #7
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Same here I'm afraid:

    HTTP_X_FORWARDED_FOR not set

    HTTP_CLIENT_IP not set
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTTP_X_FORWARDED_FOR: 217.135.60.98 Hostname: modem-866.caterpie.dialup.pol.co.uk

    HTTP_CLIENT_IP not set

    REMOTE_ADDR: 195.92.168.165 Hostname: webcacheB03a.cache.pol.co.uk

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm. With Sean's post, this isn't getting any clearer

    We now know at least the HTTP_X_FORWARDED_FOR != HTTP_CLIENT_IP


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •