views:

29

answers:

2

Hi, I am using VPN, and thus if i check http://whatismyip.com it will give me different ip than $_SERVER['REMOTE_ADDR'] or getenv('REMOTE_ADDR'). whatismyip gives my original ip address while $_SERVER or getenv gives my VPN ip address !!

is there anyway to get my original address ip using php in case that i am running VPN? and is there any way to get the PROXY IP address using PHP if i am using proxy also?

Thanks

+1  A: 

No. Whatever PHP (rather the web server) returns is the address that the request was made from. There's no way for the script to know if you're behind a VPN or proxy.

casablanca
so how does whatismyip.com returns my original ip although i am running VPN??!!
Alaa
Because whatismyip.com isn't routed through your VPN. Normally only those IP addresses that belong to the private network are tunneled through the VPN, while the rest of the traffic takes the standard route.
casablanca
A: 

Try the following - I'm not behind a proxy or VPN, so can't check right now:

$_SERVER['HTTP_X_FORWARDED_FOR']; // in place of REMOTE_ADDR

You can also try referencing SERVER_NAME using:

$_SERVER['HTTP_X_FORWARDED_HOST'];
$_SERVER['HTTP_X_FORWARDED_SERVER'];

Not sure what you'll get on a VPN. I know that anonymous proxies won't populate these variables.

adam