How to record a visitor's IP address

Source: Internet
Author: User
Tags object servervariables client access
IP Address | Access to |IP address it is necessary for an administrator of a Web site to have IP records for visitors. By recording the IP of the visitor, it provides important information for the traffic statistics of the website, the distribution of the visitor source area, and the tracing of the illegal visitors.

Before compiling the program, we should first grasp a few points.
1, obtain the client IP address statement: Request.ServerVariables ("REMOTE_ADDR");
2, ASP statement written Cookies:Response.Cookies ("Cookiesname"), read out cookies:Request.Cookies ("Cookiesname");
3, SFO of writing;

The following are code and comments.
[Code]: If Request.Cookies ("visited") <> "True" Then ' determines whether the initial access
Ipfileaddr=server.mappath ("Visited.txt") ' Locate record IP text file
Getip=request.servervariables ("remote_addr") ' Take client IP address
Set Ipfs=server.createobject ("Scripting.FileSystemObject") ' establishes the FSO object
Set Ipfile=ipfs.opentextfile (ipfileaddr,8) ' To open a text file as a way to add
Ipfile.write (getip& "") ' Write to IP address
Ipfile.writeline (now ()) ' Write record time
Ipfile.close ' Close the FSO object
Response.Cookies ("visited") = "true" to set Client access status to True
End If

In the above code, by writing cookies to the client, you can prevent (but not complete) the user from writing the data to the file again when the page is refreshed, provided that the client opens the cookies.
The code provided in this article can be independent of an ASP document, and then use include nesting on pages that need to record IP addresses.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.