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: 电话区号(这里根据电话区号做判断,分站可以做到县级)