Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2007, 04:42 PM
Junior Member
 
Join Date: Apr 2007
Posts: 3
alienware is on a distinguished road
Detect Proxy [For ur Website]

Easily detect most kinds of proxies and even determine a user's real IP address.

Most proxy servers that are free to the public also send along certain things in their HTTP headers. They send (typically) 3 extra things that can be used to

detect them.

They are

Code:
:
HTTP_X_FORWARDED_FOR 
HTTP_PROXY_CONNECTION 
HTTP_VIA
These can be obtained from PHP's $_SERVER global array.

The basic way the script below works, is it checks to see if any of these are set. If they are, then you're definately using a proxy. It also checks to see

if the word "proxy" is contained in the remote host name. This occurs frequently and is obviously a dead give away.

Most proxies are intended to be used to speed up a slow connection you might have and avoid spyware and cookies.

This script can't detect EVERY proxy, because not every proxy is detectable. High anonymity proxies (sometime's called "elite" proxies...because they make

you feel special) are proxies that are designed to keep their users hidden at all times. Reliable ones aren't easy to come by and are usually private.

If you want to use the function below, could use something like the following:

PHP Code:
<?php 

$a
=array(); 
print 
"<pre>"
detectProxy($a) ? print_r($a) : print "Not using a proxy.<br>"
print 
"</pre>"


?>
The function detectProxy($a) takes one arguement. It takes the REFERENCE to an array. That means you have to pass it an array that already exists

somewhere. This method returns a BOOLEAN true on success, FALSE on failure. duh.

If the code is confusing to you, that's because I'm using a special kind of boolean expressions (to save space) that I might cover in another tutorial.

PHP Code:
<?php 

function detectProxy(&$ar
{
//begin of function 


$gotcha=false

if(
array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER
|| 
array_key_exists('HTTP_PROXY_CONNECTION',$_SERVER
|| 
array_key_exists('HTTP_VIA',$_SERVER)) 
{
$gotcha=TRUE;} 




$gotcha = (stristr($_SERVER['REMOTE_HOST'],"proxy") !== FALSE ) ? TRUE :  $gotcha 



if(
$gotcha


$ar['PORT']=     (array_key_exists('REMOTE_PORT',$_SERVER) ? $_SERVER['REMOTE_PORT'] : "unknown"); 
$ar['HOST']=     (array_key_exists('REMOTE_HOST',$_SERVER) ? $_SERVER['REMOTE_HOST'] : "unknown"); 
$ar['IP']=       (array_key_exists('REMOTE_ADDR',$_SERVER) ? $_SERVER['REMOTE_ADDR'] : "unknown"); 
$ar['FORWARDED_FOR']=(array_key_exists('HTTP_X_FORWARDED_FOR',$_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : "unknown"); 
$ar['INFO']=     (array_key_exists('HTTP_VIA',$_SERVER) ? $_SERVER['HTTP_VIA'] : "unknown"); 


else 


$ar['PORT']=     (array_key_exists('REMOTE_PORT',$_SERVER) ? $_SERVER['REMOTE_PORT'] : "unknown"); 
$ar['HOST']=     (array_key_exists('REMOTE_HOST',$_SERVER) ? $_SERVER['REMOTE_HOST'] : "unknown"); 
$ar['IP'  ]=     (array_key_exists('REMOTE_ADDR',$_SERVER) ? $_SERVER['REMOTE_ADDR'] : "unknown"); 




return 
$gotcha

}
//end of function 


?>

Reply With Quote
  #2 (permalink)  
Old 04-16-2007, 02:50 PM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
Very nice tutorial.

A little more explanation wouldn't go amis.

But a good tutorial none the less, and a usefull one at that

+ reputation!

Base
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png
PointServ.co.uk - One of the UK's cheapest webhosting companies.
Reply With Quote
  #3 (permalink)  
Old 05-04-2007, 02:10 AM
Junior Member
 
Join Date: Dec 2006
Posts: 21
nose is on a distinguished road
Useful !!! regards
Reply With Quote
  #4 (permalink)  
Old 06-11-2007, 11:34 AM
Junior Member
 
Join Date: Jun 2007
Posts: 20
darkthug is on a distinguished road
thnkx man i needed this script to detect people using proxy visiting my site
Reply With Quote
  #5 (permalink)  
Old 06-11-2007, 09:13 PM
Junior Member
 
Join Date: Jun 2007
Posts: 20
Hoodle is on a distinguished road
Thank you - saved me a lot of head scratching!

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 01:24 AM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com