不使用global.asa实现在线人数统计
<%
sessionid = session.sessionid
timeout = 5
设置保持session的时间,你可以增加这个数值
conn_string = "driver={microsoft access driver (*.mdb)};dbq=" & server.mappath("count.mdb")
conn_string = "activeuser"
设置你的 dsn = "activeuser" 是一个很好的方法,因为你需要你需要把这个文件包含到所有的asp脚本里
set conncount =server.createobject("adodb.connection")
conncount.open conn_string
超时以后删除session
aaa = dateadd("n", -timeout, now())
conncount.execute ("delete * from count where postdate < #" & aaa & "#")
保持 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
计算 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
