[PHP] How to detect a proxy?
I was trying to come up with something that would detect ppl who uses proxy on my site and found various tuts but no one helped. My friend helped me with the code below and he says it works for him but some how it dosnt for me, any ideas?
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
?>
Thanks in advice.
~Ryaku
Re: [Question]detectProxy($a)
You're using nonexisting server superglobals, so unless you have some weird server that detects proxies it will never work.
Re: [Question]detectProxy($a)
You're not going to be able to detect if someone is using a proxy, since that's the point of using a proxy.
and learn to use the [php] and [/php] tags.
Re: [Question]detectProxy($a)
ok guys thanks any ways, tho it was going to work :/
Re: [Question]detectProxy($a)
not realy... there are some proxys u can detect....
Re: [Question]detectProxy($a)
You'd better be able to substantiate that remark if you want to avoid recieving an infraction for needlessly kicking a dead topic.