这个问题很多方法~我最欣赏这样写,因为不用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%>人在我这里流连忘返!
这个问题很多方法~我最欣赏这样写,因为不用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%>人在我这里流连忘返!
好,我刚刚好正在想一个不用Global.asa来实现的在线人数统计!!3939
如果不用数据库,而用数组又应该怎样实现在线人数统计、并显示在线用户? 请各位高手指点迷津!!!!
不错啦