For administrators of a website, IP records for visitors are necessary. By performing IPs of visitors, the access volume of the website is important, and the distribution of the visitor source area provides important information.
Before the program, we must first grasp a few points. 1. Get the client IP address statement: Request.ServerVariables ("remote_addr"); 2, ASP statement writes cookies: response.cookies ("cookiesname"); read cookies: request.cookies ("cookiesname"); 3, SFO write;
The following is program code and comments. [CODE]: if Request.cookies ("Visited") <> "true" tell if it is the first to access ipfiledr = server.mappath ("visited.txt") 'positioning record ip text file getip = request.servervariables (" Remote_addr ") 'Take the client IP address set ipfs = server.createObject (" scripting.filesystemObject ")' Establishing FSO object set ipfile = ipfs.opentextfile (ipfileaddr, 8) 'Open text file ipfile.write (Getip &" in adding mode ") 'Write IP address ipfile.writeline (now ())' Write Record Time ipfile.close 'Close FSO Object Response.Cookies (" Visited ") =" true "Setting Client Access Status True End IF
In the above code, by writing cookies to the client, it is possible to prevent (but not fully) users from writing data to the file while refreshing the page, of course, the prerequisite is that the client opens cookies. The code provided herein can be independent of an ASP document, and then use the include nest on the page that needs to record the IP address.