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; ?>
It wont work if, the user is browsing through anonymous proxy (which dont send X-FORWARDED-FOR header) including web based proxies.
Will this show the user error message or something ? will it block him from proceeding to view the site ?
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
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:
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:
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.