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

来源:asp之家 时间:2009-10-29 12:28:00 

可以的,看看下面的代码和说明:

<%
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%>人在asp之家流连忘返!


 

标签:Global.asa,统计,在线人数,asp
0
投稿

猜你喜欢

  • mssql中获取指定日期所在月份的第一天的代码

    2011-09-30 11:23:57
  • ASP连接MySQL数据库代码示例2

    2010-03-08 14:26:00
  • sqlserver合并DataTable并排除重复数据的通用方法分享

    2012-01-05 18:59:56
  • SQL0290N表空间状态问题:停顿的独占处理

    2008-12-26 17:24:00
  • Mysql入门系列:优化MYSQL服务器

    2008-11-24 13:25:00
  • photoshop快捷键大全及使用技巧

    2007-10-26 07:40:00
  • Win7 x64 IIS运行ASP+Access故障完美解决方法(转)

    2012-03-27 18:30:35
  • SQL Join的一些总结(实例)

    2012-08-21 10:19:29
  • java.sql.SQLException: 内部错误: Unable to construct a Datum from the specified input

    2010-07-16 13:23:00
  • IE6,7下实现white-space:pre-wrap;

    2009-12-31 18:30:00
  • ASP分页和日期格式化为RFC822格式的办法

    2008-11-21 15:46:00
  • dl+ol应用

    2008-06-21 17:04:00
  • IE7兼容模式与兼容视图

    2010-06-28 18:48:00
  • [翻译]标记语言和样式手册 chapter 5 表单

    2008-01-23 17:20:00
  • 简评:JavaScript将成Silverlight的最大对手?

    2008-10-17 10:29:00
  • XML卷之实战锦囊(1):动态排序

    2008-09-05 17:20:00
  • 如何制作关联的下拉菜单?

    2010-06-29 21:19:00
  • 支持鼠标拖拽的简单目录树代码

    2011-07-01 12:34:09
  • 15个设计得最糟糕最变态的CAPTCHA验证码

    2008-09-01 17:17:00
  • 闲聊html和body标签

    2009-02-21 10:50:00
  • asp之家 网络编程 m.aspxhome.com