1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP to detect users accessing site via proxy server

Discussion in 'PHP' started by cybercool, Feb 17, 2006.

  1. #1
    I am after php code which detects if a user is accessing your site via a proxy server

    this is the sort of code I have got.. is there a better way ?

    <?php
    // start code

    // if getenv results in something, proxy detected

    if (getenv('HTTP_X_FORWARDED_FOR')) {
    $ip=getenv('HTTP_X_FORWARDED_FOR');
    }

    // otherwise no proxy detected

    else {
    $ip=getenv('REMOTE_ADDR');
    }

    // print the IP address on screen
    echo $ip;
    ?>
     
    cybercool, Feb 17, 2006 IP
  2. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #2
    As far as I know, this is the code yes.
     
    Lordo, Feb 17, 2006 IP
  3. Cybernaut

    Cybernaut Peon

    Messages:
    408
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It wont work if, the user is browsing through anonymous proxy (which dont send X-FORWARDED-FOR header) including web based proxies.
     
    Cybernaut, Sep 6, 2006 IP
  4. Scriptona

    Scriptona Notable Member

    Messages:
    4,957
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    280
    #4
    Will this show the user error message or something ?

    will it block him from proceeding to view the site ?
     
    Scriptona, Sep 6, 2006 IP
  5. deny

    deny Active Member

    Messages:
    365
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #5
    If you wanna to see really detecting script in action that detect 95% of all proxies then visit my site and take a look by 2 script - basic and advanced.
    Same script has been integrated into contact form to stop spamming.
    Unfortunatelly the script is not for sale and not for sharing.
    Proxy Detector
     
    deny, Sep 9, 2006 IP
  6. trichnosis

    trichnosis Prominent Member

    Messages:
    13,785
    Likes Received:
    333
    Best Answers:
    0
    Trophy Points:
    300
    #6
    i have tried this code it did not work:(


    the tool of deny is great but i think he is not selling it:(:(
     
    trichnosis, Sep 19, 2007 IP
  7. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Haven't used this myself so not sure about its effectiveness.
    if (
          $_SERVER['HTTP_X_FORWARDED_FOR']
       || $_SERVER['HTTP_X_FORWARDED']
       || $_SERVER['HTTP_FORWARDED_FOR']
       || $_SERVER['HTTP_VIA']
       || in_array($_SERVER['REMOTE_PORT'], array(8080,80,6588,8000,3128,553,554))
       || @fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 30))
    {
        exit('Proxy detected');
    }
    PHP:
     
    krt, Sep 19, 2007 IP
  8. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
  9. dannywwww

    dannywwww Well-Known Member

    Messages:
    804
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #9
    i added this to my pages and it works
     
    dannywwww, Sep 20, 2007 IP
  10. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #10
    Thumbs up on HTTP_CLIENT_IP, I have added it to the list:
    if (
          $_SERVER['HTTP_X_FORWARDED_FOR']
       || $_SERVER['HTTP_X_FORWARDED']
       || $_SERVER['HTTP_FORWARDED_FOR']
       || $_SERVER['HTTP_CLIENT_IP']
       || $_SERVER['HTTP_VIA']
       || in_array($_SERVER['REMOTE_PORT'], array(8080,80,6588,8000,3128,553,554))
       || @fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 30))
    {
        exit('Proxy detected');
    }
    PHP:
     
    krt, Sep 20, 2007 IP
  11. tgotchi

    tgotchi Active Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #11
    You can consider the new method in detecting the anonymous proxy server.

    http://www.ip2proxy.com
     
    tgotchi, Nov 6, 2008 IP
  12. deny

    deny Active Member

    Messages:
    365
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #12
    It is limited service and not very accurate.
    For example i tried via web proxy server 2getonline.info to test both service.


    http://www.proxyserverprivacy.com show me this:
    ----------------------------------------------------
    ProxyServerPrivacy detection
    Your Ip Address: 66.197.167.120
    Host: kraton.revti.net
    Your Country:
    City: Reno, NV
    Proxy HTTP_X_FORWARDED Variable: (none)
    Proxy HTTP_VIA Variable: (none)
    Proxy HTTP_PROXY_CONNECTION: (none)
    Cache Pragma: (none)
    Your Browser: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729)
    Type of Your connection: (none)
    Server Protocol: HTTP/1.1
    Your language: (none)
    Accept: */*
    Accept-Encoding: deflate, gzip
    Referer - HTTP Request come from:
    Your Port: 52715

    Conclusion after analyzing ip address:
    It seems that you are behind Proxy 66.197.167.120 (kraton.revti.net).

    ---------------------------------------------------------------------

    I tried with same IP address to test it on second service from http://www.ip2proxy.com/ and what i have received is:

    Ip Address: 66.197.167.120
    Proxy: No


    It is clearly web proxy where commercial service failed and free one not.
     
    deny, Nov 6, 2008 IP