I'm trying to redirect users by their IP address. Here is the code for getting the IP:
if (!empty($SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
The problem is that I'm getting private IPs in some cases. I haven't been able to confirm, but I believe what is happening is that I'm getting the IP of the user's computer. For example, a user's computer at work may have a local IP of 10.XXX.X, but the external IP would be 192.XXX.X.
The few times that this issue has come up (i.e. users being redirected to the wrong place), I've asked the user to run the above script and the IP always comes back as 10.XXX. Could this by a Proxy issue? I've tried every way I can think of to test this and I've never been able to replicate the issue.
I'm lost, so I would really appreciate some help.
Thx!