FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

PHP to detect users accessing site via proxy server

 


wangbin218200
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;
?>
hexkid
Yes, don't base your logic on the user's IP (direct or through proxy).

Remember that proxies may leave the HTT_X_FORWARDED_FOR empty; different users may connect from the same proxy; the same user may connect from different proxies on every request; ...


If these "shortcomings" do not bother you, I guess your code is ok.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.