新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:开放源码 - 访客统计查询(五)

开放源码 - 访客统计查询(五)

新客网 XKER.COM 2004-03-16 来源: 收藏本文
<%
<Script Language = "VBScript" RunAt = "Server">
Function DealIP(srcIP)
Dim lngIP, aryIP, I

lngIP = 0
aryIP = Split(srcIP, ".")
If UBound(aryIP) <> 3 Then
DealIP = 0
Exit Function
End If

For I = 0 To 3
lngIP = lngIP + (CInt(aryIP(I)) * (256 ^ (3 - I)))
Next

DealIP = lngIP - 1
If Err Then DealIP = 0
End Function

<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->

Sub Statistics_Add()
Session("IsRecorded") = False

Session("sttPage") = Request.ServerVariables("SCRIPT_NAME")
Session("refPage") = Request.ServerVariables("HTTP_REFERER")

If Not Session("IsRecorded") Then
Dim objConn, objRS, strSQL
Dim IEVersion, IPAddress, VisitDate, VisitTime, IPAddressDeal, tmpID
Dim sttPage, refPage

IEVersion = Request.ServerVariables("HTTP_USER_AGENT")
IPAddress = Request.ServerVariables("REMOTE_ADDR")
VisitDate = Date()
VisitTime = Time()
sttPage = Session("sttPage")
refPage = Session("refPage")

Set objConn = Server.CreateObject("ADODB.Connection")
With objConn
' 数据库连接,字符串自定
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("... ...")
.Open
End With

IPAddressDeal = DealIP(CStr(IPAddress))
Set objRS = Server.CreateObject("ADODB.Recordset")
With objRS
.ActiveConnection = objConn
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
.Source = "Select * From IPDatas Where IP_Lower <= " & IPAddressDeal & " And IP_Upper >= " & IPAddressDeal
.Open
End With
If objRS.EOF Then
tmpID = 29510
Else
tmpID = objRS("IP_ID")
End If
objRS.Close

With objRS
.ActiveConnection = objConn
.CursorType = adOpenForwardOnly
.LockType = adLockPessimistic
.Source = "Select * From IPs"
.Open
.AddNew
.Fields.Item("IEVersion") = IEVersion
.Fields.Item("IPAddress") = IPAddress
.Fields.Item("IP_ID") = tmpID
.Fields.Item("VisitDate") = VisitDate
.Fields.Item("VisitTime") = VisitTime
.Fields.Item("sttPage") = sttPage
.Fields.Item("refPage") = refPage
.Update
End With

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing

Session("IsRecorded") = True
End If
End Sub

Sub Application_OnStart()
Application("NowOnline") = 0
End Sub

Sub Session_OnStart()
Session.TimeOut = 20

Session("IsRecordedCCCNet") = False

Call Statistics_Add

Application.Lock
Application("NowOnline") = Application("NowOnline") + 1
Application.UnLock
End Sub

Sub Session_OnEnd()
Application.Lock
Application("NowOnline") = Application("NowOnline") - 1
Application.UnLock
End Sub
</Script>
%>
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐