Whenever a browser sends a request for a page, it also sends a number of other headers to the script, containing information such as the browser type. It also includes information such as the visitors IP address. This can be particularly useful when creating an online security scan, or logging their IP address in an online forum.
There are two server variables of interest;
HTTP_X_FORWARDED_FOR. As many visitors access the internet via a third party (ie their ISP),
REMOTE_ADDR does not always contain their IP address... it contains their ISP's address. If this is the case, most browsers then store the users IP address in the
HTTP_X_FORWARDED_FOR variable. So, first, we check
HTTP_X_FORWARDED_FOR, and then if that is empty, we try
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If sIPAddress="" Then sIPAddress = Request.ServerVariables("REMOTE_ADDR")
One other thing worth bearing in mind. If the user also accesses the internet via a Proxy server, then
HTTP_X_FORWARDED_FOR will contain the Proxy's IP address. If this is the case, there is no way to get the users 'real' IP address.
IPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If IPAddress="" Then IPAddress = Request.ServerVariables("REMOTE_ADDR")
IF IsNull(IPAddress) Then