The ASP automatically recognizes IP and jumps to the city where the visitor is located

Source: Internet
Author: User

Automatically identify IP and jump to the visitor's city
first go to the next pure IP database, and then do the following:
1. Run pure QQIP database with ShowIP.exe, point decompression, input file name, such as IP.txt, OK, get a txt file.
2. Open access, tools-Customize, Command tab, drag the Import options to the toolbar above.
3. Build a table, four fields
StartIP type: Text (IP segment information for related cities)
EndIP Type: Text (IP segment information for related cities)
Country type: text (related city name)
Reurl type: Text (You want to jump to the city path, such as: Beijing http://bj.abc.com)
4. Click to import button, file type select text file, find just exported IP.txt file, import to just build the table ~
operation will convert real IP to numbers, such as Beijing's IP segment is: 1.1.0.0-1.1.0.255
startip:1*256 *256*256+1*256*256+0*256+0 = 16842752 (this number is ultimately to be placed in the database)
endip:1*256*256*256+1*256*256+0*256+255 = 16843007 ( This number is ultimately to be put into the database in batch processing, if not, and no time (like me) you go directly to the next network IP library, it has been processed, the following is part of the program:

User_ip = Request.ServerVariables ("remote_addr") ' Get visitor IP
Userip_ary=split (user_ip, ".")
Tmp_userip=userip_ary (0) *256*256*256+userip_ary (1) *256*256+userip_ary (2) *256+userip_ary (3) "Convert IP to digital as required
&NBSP
Find the city where the user IP belongs from the database
 
Set Rs=server.createobject ("ADODB. Recordset ")
sql=" select * from IP where startip<= "&tmp_userip&" and endip>= "&tmp_userip
Rs.Open sql,conn,1,1
If rs.eof then
Response.Redirect "Index.asp" if the city or IP is not recognized, go to the front page, or you can specify the page
else
Response.Redirect rs ("Reurl") ' If you have to go to the specified page
End If
rs.close
Set rs=nothing
Place the above program in your virtual host default access page! or other pages. (Of course you also want to set the default access in the Virtual host Control Panel to this file first)

Related Article

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.