Another important note to this
the HTTP_X_FORWARDED_FOR may contain an array of IP, this can happen if you connect through a proxy.
What also happens when this happens is that the REMOTE_ADDR may contain the proxy IP.
to avoid this problem you can parse the HTTP_X_FORWARDED_FOR for the last entery IP.
this can easily be done using...
- ip=Request.ServerVariables("HTTP_X_FORWARDED_FOR") ;
-
if (!string.IsNullOrEmpty(ip))
-
{
-
string[] ipRange = ip.Split(',');
-
int le = ipRange.Length - 1;
-
string trueIP = ipRange[le];
-
}
-
else
-
{
-
ip=Request.ServerVariables("REMOTE_ADDR");
-
}
This code example is C#.NET but the method is the same
What this does is check if we have anything in the HTTP_X_FORWARDED_FOR, and if we do we take out the last entry (works if only one entry is found aswell)
if we don't have an HTTP_X_FORWARDED_FOR we set the IP from the REMOTE_ADDR instead