Detect Real Client IP from Proxy Using PHP
Fetching out proxy users and exposing their real IP is what I really enjoy, I remember using Google Search in Opera Mini Mobile which uses its proxy to forward. But to my suprise, it got to know am in Nigeria and redirect me to .com.ng 😀 .
So glad to find out PHP doing this, which makes our site or project more mature and advance 🙂 . In PHP simply use the $_SERVER[‘HTTP_X_FORWARDED_FOR’] 🙂
$_SERVER[‘HTTP_X_FORWARDED_FOR’] is only available if the server detects the client using a proxy else it turns empty or unavailable. This looks for original IP that is been forwarded.
Now lets use this function, firstly lets check if the client is really using a Proxy and echo his real IP
1 |
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))<br /> {<br /> //Actually he is! :D, lets expose him and tell him his right IP<br /> echo 'The main IP of the Proxy or Opera Mini is'.$_SERVER['HTTP_X_FORWARDED_FOR'];<br /> } |
we are done with that and the above code will only run if he is on proxy, now lets write one that will tell the Client he/she is not using proxy if necessary 🙂
I guess we are done here, below is the full code
1 |
if(empty($_SERVER['HTTP_X_FORWARDED_FOR']))<br /> {<br /> echo 'You are currently not using a proxy';<br /> } |
1 |
<?php<br />//Lets be sure if he is using proxy<br />if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))<br /> {<br /> //Actually he is! :D, lets expose him and tell him his right IP<br /> echo 'The main IP of the Proxy or Opera Mini is'.$_SERVER['HTTP_X_FORWARDED_FOR'];<br /> }<br />else<br /> {<br /> //Oh, he is browsing with his normal IP :)<br /> echo 'The user is currently not using a proxy';<br /> }<br />?> |