主题:[支持原创] 在线人数统计程序,未调试,仅供参考
<%@ language="VBScript" %>
<%
'数据库保存在当前目录下的ONLINE.MDB
'数据表是ONLINE
'数据表结构
'SessionID char(40) 用户标识
'ClientIP char(15) 客户IP
'LATime datetime 最后活动时间
'LAURI char(200) 最后活动的URI
'----------------------------------------------------------------------------------
'使用方法:在需要统计的地方用<!-- #include virtual="online.asp" -->
'然后:
' RefreshList()
' If QueryOnLine() Then
' UpDateOnLine()
' Else
' AddOnLine()
' End If
'如果你要统计在线人数或者输出在线人员列表,请自己读取ONLINE表搞定
'----------------------------------------------------------------------------------
'
' 本程序由圪圪执笔,"ASP交流"群集体创作 [2004年2月0日 21:04]
' 功劳是大家的,错误是我自己的………………
'
' 由于是在网吧上网,无法调试,代码也是写了一遍,没有检查
' 可能无法运行,这里只是提供一种思路
'
'----------------------------------------------------------------------------------
Function QueryOnLine() '检查数据库中是否有当前用户的记录
Dim oCnn,oRs
Set oCnn=Server.CreateObject("ADODB.Connection")
Set oRs=Server.CreateObject("ADODB.RecordSet")
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
USID=Session.SessionID
oRs.Open "SELECT * FROM OnLine WHERE SessionID='" & USID & "'",oCnn,2,1
If oRs.Eof Then
QueryOnLine=False
Else
QueryOnLine=True
End If
oRs.Close
oCnn.Close
Set oRs=Nothing
Set oCnn=Nothing
End Function
Function AddOnLine() '新加在线用户
Dim oCnn
Set oCnn=Server.CreateObject("ADODB.Connection")
USID=Session.SessionID
CIP=Request.ServerVariables("REMOTE_ADDR")
LAT=Time()
LAU=Request.ServerVariables("SCRIPT_NAME")
If Request.ServerVariables("QUERY_STRING")<>"" Then
LAU=LAU & "?" & Request.ServerVariables("QUERY_STRING")
End If
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
oCnn.Execute "INSERT INTO ONLINE (SessionID,ClientIP,LATime,LAURI) VALUES ('" & USID & "','" & CIP &_
"',#" & LAT & "#,'" & LAU & "')"
oCnn.Close
Set oCnn=Nothing
End Function
'----------------------------------------------------------------------------------
Function UpDateOnLine() '更新当前用户
Dim oCnn,oRs
Set oCnn=Server.CreateObject("ADODB.Connection")
Set oRs=Server.CreateObject("ADODB.RecordSet")
USID=Session.SessionID
LAT=Time()
LAU=Request.ServerVariables("SCRIPT_NAME")
If Request.ServerVariables("QUERY_STRING")<>"" Then
LAU=LAU & "?" & Request.ServerVariables("QUERY_STRING")
End If
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
oRs.Open "SELECT * FROM ONLINE WHERE SessionID='" & USID & "'",oCnn,2,1
If oRs.EOF Then
AddOnLine()
Else
oCnn.Execute "UPDATE ONLINE SET LATime=#" & LAT & "#,LAURI='" & LAU & "' WHERE SessionID='" & USID & "'"
End if
oRs.Close
oCnn.Close
Set oRs=Nothing
Set oCnn=Nothing
End Function
'----------------------------------------------------------------------------------
Function RefreshList() '刷新用户在线列表
Dim oCnn,oRs
Set oCnn=Server.CreateObject("ADODB.Connection")
Set oRs=Server.CreateObject("ADODB.RecordSet")
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
CTM=Time
TTM=dateadd("s",CTM,-15*60)
oCnn.Execute "DELETE FROM ONLINE WHERE LATime<#" & TTM & "#"
oRs.Close
oCnn.Close
Set oRs=Nothing
Set oCnn=Nothing
End Function
%>
<%
'数据库保存在当前目录下的ONLINE.MDB
'数据表是ONLINE
'数据表结构
'SessionID char(40) 用户标识
'ClientIP char(15) 客户IP
'LATime datetime 最后活动时间
'LAURI char(200) 最后活动的URI
'----------------------------------------------------------------------------------
'使用方法:在需要统计的地方用<!-- #include virtual="online.asp" -->
'然后:
' RefreshList()
' If QueryOnLine() Then
' UpDateOnLine()
' Else
' AddOnLine()
' End If
'如果你要统计在线人数或者输出在线人员列表,请自己读取ONLINE表搞定
'----------------------------------------------------------------------------------
'
' 本程序由圪圪执笔,"ASP交流"群集体创作 [2004年2月0日 21:04]
' 功劳是大家的,错误是我自己的………………
'
' 由于是在网吧上网,无法调试,代码也是写了一遍,没有检查
' 可能无法运行,这里只是提供一种思路
'
'----------------------------------------------------------------------------------
Function QueryOnLine() '检查数据库中是否有当前用户的记录
Dim oCnn,oRs
Set oCnn=Server.CreateObject("ADODB.Connection")
Set oRs=Server.CreateObject("ADODB.RecordSet")
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
USID=Session.SessionID
oRs.Open "SELECT * FROM OnLine WHERE SessionID='" & USID & "'",oCnn,2,1
If oRs.Eof Then
QueryOnLine=False
Else
QueryOnLine=True
End If
oRs.Close
oCnn.Close
Set oRs=Nothing
Set oCnn=Nothing
End Function
Function AddOnLine() '新加在线用户
Dim oCnn
Set oCnn=Server.CreateObject("ADODB.Connection")
USID=Session.SessionID
CIP=Request.ServerVariables("REMOTE_ADDR")
LAT=Time()
LAU=Request.ServerVariables("SCRIPT_NAME")
If Request.ServerVariables("QUERY_STRING")<>"" Then
LAU=LAU & "?" & Request.ServerVariables("QUERY_STRING")
End If
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
oCnn.Execute "INSERT INTO ONLINE (SessionID,ClientIP,LATime,LAURI) VALUES ('" & USID & "','" & CIP &_
"',#" & LAT & "#,'" & LAU & "')"
oCnn.Close
Set oCnn=Nothing
End Function
'----------------------------------------------------------------------------------
Function UpDateOnLine() '更新当前用户
Dim oCnn,oRs
Set oCnn=Server.CreateObject("ADODB.Connection")
Set oRs=Server.CreateObject("ADODB.RecordSet")
USID=Session.SessionID
LAT=Time()
LAU=Request.ServerVariables("SCRIPT_NAME")
If Request.ServerVariables("QUERY_STRING")<>"" Then
LAU=LAU & "?" & Request.ServerVariables("QUERY_STRING")
End If
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
oRs.Open "SELECT * FROM ONLINE WHERE SessionID='" & USID & "'",oCnn,2,1
If oRs.EOF Then
AddOnLine()
Else
oCnn.Execute "UPDATE ONLINE SET LATime=#" & LAT & "#,LAURI='" & LAU & "' WHERE SessionID='" & USID & "'"
End if
oRs.Close
oCnn.Close
Set oRs=Nothing
Set oCnn=Nothing
End Function
'----------------------------------------------------------------------------------
Function RefreshList() '刷新用户在线列表
Dim oCnn,oRs
Set oCnn=Server.CreateObject("ADODB.Connection")
Set oRs=Server.CreateObject("ADODB.RecordSet")
oCnn.Open "Driver={Microsoft Access Driver (*.mdb)};dbq='" & Server.MapPath("ONLINE.MDB") & "'"
CTM=Time
TTM=dateadd("s",CTM,-15*60)
oCnn.Execute "DELETE FROM ONLINE WHERE LATime<#" & TTM & "#"
oRs.Close
oCnn.Close
Set oRs=Nothing
Set oCnn=Nothing
End Function
%>