asp 根據(jù)IP地址自動(dòng)判斷轉(zhuǎn)向分站的代碼
更新時(shí)間:2008年11月27日 00:48:16 作者:
根據(jù)IP地址自動(dòng)判斷轉(zhuǎn)向分站的代碼
這個(gè)是一個(gè)不錯(cuò)的解決之道,可以緩解服務(wù)器壓力過大等一些問題
Function getIpvalue(clientIP)'得到客戶端的IP轉(zhuǎn)換成長(zhǎng)整型,返回值getIpvalue
On Error Resume Next
Dim strIp, array_Ip
strIp=0
array_Ip = Split(clientIP,".")
If UBound(array_Ip)<>3 Then
getIpvalue=0
Exit Function
End If
For i=0 To 3
strIp=strIp+(CInt(array_Ip(i))*(256^(3-i)))
Next
getIpvalue=strIp
If Err Then getIpvalue=0
End Function
clientIP=request.ServerVariables("REMOTE_HOST")
IpValue=getIpvalue(clientIP)
strSql="select top 1 City from [Ipaddress] where "&IpValue&"
between Ip1 and Ip2"
Set RsIp=conn.execute(strSql)
If RsIp.bof and RsIp.eof then
UrlCity="未知"
Else
UrlCity=RsIp.Fields.Item("City").Value
End If
if instr(UrlCity,"廣州")<>0 then
response.Redirect("http://www.dbjr.com.cn")
end if
if instr(UrlCity,"深圳")<>0 then
response.Redirect("http://img.jb51.net")
end if
if instr(UrlCity,"上海")<>0 then
response.Redirect("http://xiazai.jb51.net")
end if
所用到的IP數(shù)據(jù)庫可以去網(wǎng)上down一個(gè)回來
On Error Resume Next
Dim strIp, array_Ip
strIp=0
array_Ip = Split(clientIP,".")
If UBound(array_Ip)<>3 Then
getIpvalue=0
Exit Function
End If
For i=0 To 3
strIp=strIp+(CInt(array_Ip(i))*(256^(3-i)))
Next
getIpvalue=strIp
If Err Then getIpvalue=0
End Function
clientIP=request.ServerVariables("REMOTE_HOST")
IpValue=getIpvalue(clientIP)
strSql="select top 1 City from [Ipaddress] where "&IpValue&"
between Ip1 and Ip2"
Set RsIp=conn.execute(strSql)
If RsIp.bof and RsIp.eof then
UrlCity="未知"
Else
UrlCity=RsIp.Fields.Item("City").Value
End If
if instr(UrlCity,"廣州")<>0 then
response.Redirect("http://www.dbjr.com.cn")
end if
if instr(UrlCity,"深圳")<>0 then
response.Redirect("http://img.jb51.net")
end if
if instr(UrlCity,"上海")<>0 then
response.Redirect("http://xiazai.jb51.net")
end if
所用到的IP數(shù)據(jù)庫可以去網(wǎng)上down一個(gè)回來
相關(guān)文章
ASP實(shí)現(xiàn)智能搜索實(shí)現(xiàn)代碼
asp下智能搜索功能的實(shí)現(xiàn),方便大家學(xué)習(xí)2008-06-06asp中response.write(''中文'')或者js中文亂碼問題
這篇文章主要介紹了asp中response.write('中文')或者js中文亂碼問題,有時(shí)候我們需要輸出js也會(huì)出現(xiàn)亂碼,這里給出了幾個(gè)解決方法,需要的朋友可以參考下2020-03-03