how to define the IP address using classic ASP

2019-07-30 15:44发布

问题:

I just need a fully code how to get/define the IP address for every time user login into my website because i need to save the IP address into the database table for keep track where the IP comes. Thanks.

回答1:

You're better off calling a simple function like this:

Function IP()
    Dim strIP : strIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR") 
    If strIP = "" Then strIP = Request.ServerVariables("REMOTE_ADDR")
    IP = strIP
End Function

This will return the true IP address of the user, even if they're behind a proxy or being served through a CDN which can sometimes cause an issue.



回答2:

Response.Write Request.ServerVariables ("REMOTE_ADDR")

See more at http://www.w3schools.com/asp/coll_servervariables.asp

You even could get such information: does user using proxy server, and what his real IP address (beyond proxy).

See sample: http://1click.lv/debug/debug.asp ;)



回答3:

use the Request.Servervariables Collection.

ip would be the following:

Request.ServerVariables("REMOTE_ADDR")

have a look here for a list of iis Server variables



标签: asp-classic