当前位置: 首页 > 图文教程 > 网络编程 > ASP > 不用Global.asa实现在线人数统计

ASP
bbs的树状结构算法
bbs的树状算法的补充程序
ASP.NET:访问Excel 电子表格
ADO.NET:ADODataReader类
ADO.NET:使用ADO.NET连接文本文件
session变量中的数组如何引用
外源.js的选择调用与一个.htm网站管理初探
验证email地址是否合法完整实例
不用Global.asa实现在线人数统计
为输入及输出的数据库的资料做造型
改进性能和样式的 25+ ASP 技巧(1)
改进性能和样式的 25+ ASP 技巧(2)
改进性能和样式的 25+ ASP 技巧(3)
改进性能和样式的 25+ ASP 技巧(4)
表单递交内容检测脚本-这里只接受数字
如何使replace方法不区分大小写?
在 Web 页上使用条件数值格式
如何用asp把sqlserver数据转换为execl文件
用ADO STREAM做的无组件上传程序简单介绍
如何在主页中控制浏览权限

ASP 中的 不用Global.asa实现在线人数统计


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 23 ::
收藏到网摘: n/a

  <%
'count online user without using Global.asa
'script by Narong Khotarasakit
'webmaster of ezebox.com
'report bug : [email protected]


sessionID = session.SessionID
timeout = 5
' set how long to keep this session in minute you can increase this number

Conn_String = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("count.mdb")
'Conn_String = "activeUser"
'set your DSN = "activeuser" is a better way because you need include this file to all your asp scripts.


Set ConnCount =Server.CreateObject("ADODB.Connection")
ConnCount.Open Conn_String

' delete session after timeout
aaa = dateadd("n", -timeout, now())
connCount.Execute ("delete * from count where postdate < #" & aaa & "#")


' keep sessionID
sql0 = "select sess from count where sess='" & sessionID & "'"
set rscheck = connCount.Execute (sql0)
if rscheck.eof then
sql = "insert into count (sess,postdate) values('" & sessionID & "', '" & now() & "')"
connCount.Execute (sql)
end if
rscheck.close
set rscheck = nothing

'count sessionID
sql2 = "select count(sess) from count"
set rs = connCount.Execute (sql2)
count = rs(0)
rs.close
set rs = nothing


sql3 = "select * from count"
set rspredel = connCount.Execute (sql3)
do until rspredel.eof
xxx=DateDiff("n", rspredel("postdate"), Now())
if xxx > timeout then
count = count-1
end if
rspredel.movenext
loop
rspredel.close
set rspredel = nothing

connCount.Close
set connCount = nothing

if count = 0 then
count = 1
end if
%>

<%=count%> Active users