The difference between HTTP_X_FORWARDED_FOR and REMOTE_ADDR. There is no HTTP_X_FORWARDED_FOR variable in Request.ServerVariables, only REMOTE_ADDR, but both variables can obtain the client IP address. So what's the difference between them?
Use Request.ServerVariables(REMOTE_ADDR) in ASP to obtain the client's IP address. However, if the client uses a proxy server to access, what is obtained is the IP address of the proxy server, not the real client IP address. To obtain the client's real IP address through the proxy server, use Request.ServerVariables(HTTP_X_FORWARDED_FOR) to read it.
However, it should be noted that not every proxy server can use Request.ServerVariables(HTTP_X_FORWARDED_FOR) to read the real IP of the client. Some of the IPs read by this method are still the IP of the proxy server.
Another thing to note is that if the client does not access through a proxy server, the value obtained with Request.ServerVariables (HTTP_X_FORWARDED_FOR) will be empty. So, if you want to use this method in your program, you can do it like this:
...
userip = Request.ServerVariables(HTTP_X_FORWARDED_FOR)
If userip = Then userip = Request.ServerVariables(REMOTE_ADDR)
...
That is: if the client passes the proxy server, the value of HTTP_X_FORWARDED_FOR is taken. If the client does not pass the proxy server, the value of REMOTE_ADDR is taken.
Of course, the above approach is not omnipotent. As mentioned in the third paragraph, have you considered that if the user is using a level 2 proxy, a level 3 proxy, a level 4 proxy... .