Display or jump to a regional station based on the visitor's IP

Source: Internet
Author: User
Tags servervariables

Based on IP to judge, will automatically jump to the visitor's IP according to the location of the city's local substation
The reference code is as follows:

Function lookaddress (SIP)
Dim str1, str2, STR3, STR4
Dim num
Dim IRS
If IsNumeric (Left (SIP, 2)) Then
If sip = "127.0.0.1" Then sip = "192.168.0.1"
STR1 = Left (sip, InStr (SIP, ".")-1)
SIP = Mid (sip, INSTR (SIP, ".") + 1)
STR2 = Left (sip, InStr (SIP, ".")-1)
SIP = Mid (sip, INSTR (SIP, ".") + 1)
STR3 = Left (sip, InStr (SIP, ".")-1)
STR4 = Mid (SIP, INSTR (SIP, ".") + 1)
If IsNumeric (STR1) = 0 or IsNumeric (str2) = 0 Or isnumeric (STR3) = 0 Or isnumeric (STR4) = 0 Then
Else
num = CDbl (str1) * 16777216 + CDBL (str2) * 65536 + CDBL (STR3) * 256 + CDBL (STR4)-1
sql = "Select timezone from IPAddress where StartIP <=" & Num & "and EndIP >=" & Num
Set IRS = conn. Execute (SQL)
If IRS. EOF and IRS. BOF Then
Lookaddress = "0"
Else
Do, not IRS. Eof
lookaddress = IRS (0)
IRs. MoveNext
Loop
End If
IRs. Close
Set IRS = Nothing
End If
Else
Lookaddress = "0"
End If
End Function
Userip = Request.ServerVariables ("Http_x_forwarded_for")
If Userip = "" Then Userip = Request.ServerVariables ("REMOTE_ADDR")
Visitflag = lookaddress (Userip)
If Visitflag = "" Then
Response.Write ("window.location.href= ' http:/www.goimage.cn ';")
ElseIf visitflag= "010"
Response.Write ("window.location.href= ' http:/bj.goimage.cn ';")
End If

数据库结构:
表名:IPaddress
startip: 起始IP
endip: 结束IP
country: 所在位置
timezone: 电话区号(这里根据电话区号做判断,分站可以做到县级)



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.