当前位置: 移动技术网 > IT编程>开发语言>其他编程 > 不用Global.asa也能实现统计在线人数吗?

不用Global.asa也能实现统计在线人数吗?

2017年12月08日  | 移动技术网IT编程  | 我要评论

不用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

aaa = dateadd("n", -timeout, now())
conncount.execute ("delete * from count where postdate < #" & aaa & "#")
'
在超时后删除session.

sql0 = "select sess from count where sess='" & sessionid & "'"

' 保持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

sql2 = "select count(sess) from count"

' 计算sessionid.
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%>人在随风起舞流连忘返!

 

[1]

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网