?? function.asp
字號(hào):
<%
'-------------------------------------------------------------------------------------
'轉(zhuǎn)發(fā)時(shí)請(qǐng)保留此聲明信息,這段聲明不并會(huì)影響你的速度!
'************************** 【盛云網(wǎng)絡(luò)IP2城市數(shù)據(jù)庫(kù)】 ********************************
'作者:o擺擺o0O 演示地址:http://www.sonrun.com/demo/ip
'官方網(wǎng)站:http://www.sonrun.com 技術(shù)論壇:http://www.sonrun.com/bbs
'電子郵件:sonrun@163.com 在線QQ:4033617
'版權(quán)聲明:版權(quán)沒(méi)有,盜版不究,各種用途均可免費(fèi)使用。
'IP數(shù)據(jù)庫(kù)將會(huì)不定期更新,歡迎大家到本站免費(fèi)下載最新版!
'真正的IP地址轉(zhuǎn)換為城市數(shù)據(jù)庫(kù),優(yōu)化數(shù)據(jù)庫(kù)結(jié)構(gòu),并且采用Cookies保存城市信息,查詢速度更快!
'--------------------------------------------------------------------------------------
%>
<%
Dim IP_address,IP_rs,CIP,IP_conn,IP_connstr,IP_province,IP_city,rs,IP_py
Const DataType=0 '0為Access數(shù)據(jù)庫(kù),1為SQL Server數(shù)據(jù)庫(kù)
Const MdbPath="IP_Address.mdb" '如果是SQL Server數(shù)據(jù)庫(kù),此項(xiàng)留空
ip_address=Request.ServerVariables("REMOTE_ADDR") '獲取客戶端IP地址
Function GetRegion()
If Request.Cookies("sonrun")("IP_province")&""<>"" And Request.Cookies("sonrun")("IP_city")&""<>"" And Request.Cookies("sonrun")("IP_py")&""<>"" Then
IP_province=Request.Cookies("sonrun")("IP_province")
IP_city=Request.Cookies("sonrun")("IP_city")
IP_py=Request.Cookies("sonrun")("IP_py")
Else
Call SelectData()
Response.Cookies("sonrun")("IP_province")=IP_province
Response.Cookies("sonrun")("IP_city")=IP_city
Response.Cookies("sonrun")("IP_py")=IP_py
Response.Cookies("sonrun").Expires=Date+1
End If
End Function
Sub IPConn()
On Error Resume Next
If DataType=0 Then
IP_connstr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&Server.MapPath(MdbPath)
Else
IP_connstr="driver={SQL Server}; server=127.0.0.1;database=IP_Address;uid=sa;pwd="
End If
Set IP_conn=Server.CreateObject("Adodb.Connection")
IP_conn.Open IP_connstr
If Err.Number<>0 Then
Err.Clear
Response.Write("數(shù)據(jù)庫(kù)連接失?。?quot;)
Response.End()
End If
End Sub
Function IP2Num(IP) '將IP轉(zhuǎn)換為數(shù)字格式
Dim IPArr
IPArr=Split(IP,".")
IP2Num=Int(IPArr(0))*256*256*256+Int(IPArr(1))*256*256+Int(IPArr(2))*256+Int(IPArr(3))
End Function
Function SelectData()
If ip_address<>"" Then
CIP=IP2Num(ip_address)
Call IPConn()
Set IP_rs=IP_conn.Execute("select top 1 city,province from ip_address where "&CIP&">=ip1 and "&CIP&"<=ip2 order by id desc")
If IP_rs.Eof Then
IP_province="北京"
IP_city="北京"
IP_py="bj"
Else
IP_province=IP_rs(1)
IP_city=IP_rs(0)
Set rs=IP_conn.Execute("select pinyin from city_py where city='"&IP_city&"'")
IP_py=rs(0)
rs.Close
Set rs=Nothing
End if
IP_rs.Close
Set IP_rs=Nothing
IP_conn.Close
Set IP_conn=Nothing
Else
IP_province="北京"
IP_city="北京"
End If
End Function
%>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -