日期:2011-08-27  浏览次数:20943 次

根据IP来判断, 就会根据访问者的IP自动跳转到访问者所在城市的地区分站
参考代码如下:

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