Steps to implement from IP jump to the user's city

Source: Internet
Author: User

According to IP jump to the user's city automatically identify IP, and jump to the arrival of visitors in the city

First go to the next most innocent 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-Custom, Command tab, drag the Import options to the toolbar above.

3. Build a library, build a table, four fields

StartIP Type: Text (IP segment information for the relevant city)

EndIP Type: Text (IP segment information for the relevant city)

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, imported to the table just built ~

Operations convert real IP to numbers, such as the IP segment in Beijing: 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)

Available Programs batch processing, if not, and there is 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") ' Gets the 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) ' converts IP to digital as required

' Identify 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 there is no such city or IP is not recognized, go to the first page, you can also specify pages

Else

Response.Redirect rs ("Reurl") ' If there is a go to the specified page

End If

Rs.close

Set rs=nothing

Put the above program to your virtual host default access to the home page! or other pages (of course you also have to set the default access in the Virtual host Control Panel is this file first) OK

Note : For more wonderful tutorials, please pay attention to the Triple design Tutorials section,

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.