'*********使用数据库推断在线名单以及在线人数
'*********系统支持:asp+access,在windows2000+iis5上測试通过
'*********login.asp*********
<%&#64;LANGUAGE&#61;"Vbscript"%>
<%&#39;ON ERROR RESUME NEXT%>
.
.
.
&#39;登录推断。略
.
.
&#39;登录成功
session("Name")&#61;rs("M_Name")
rs.Close
strSQL&#61;"Update B_MEMBER Set M_IsOnLine&#61;yes,M_LastTime&#61;now() Where M_Name&#61;&#39;"&#43;strName&#43;"&#39;"
rs.Open strSQL,myconn
response.redirect"xxx.asp"
SET RS&#61;NOTHING
MYCONN.CLOSE
SET MYCONN&#61;NOTHING
%>
&#39;*********refresh.asp*******
<%&#64;LANGUAGE&#61;"Vbscript"%>
<%&#39;ON ERROR RESUME NEXT%>
.
.
.
&#39;设置5分钟未动作的id为offline,rers1为前面打开的连接&#xff0c;读取id。
set rers2&#61;Server.CreateObject("ADODB.RECORDSET")
For ipage&#61; 1 to onlinenum
if minute(now)-minute(rers1("M_LastTime"))>5 or minute(now)-minute(rers1("M_LastTime"))<0 then
reSQL&#61;"Update B_MEMBER Set M_IsOnLine&#61;no Where M_ID&#61;"&rers1("M_ID")
rers2.Open reSQL,myconn
end if
rers1.MoveNext
if rers1.EOF then exit for
next
myconn.close
SET MYCONN&#61;NOTHING
%>
&#39;*************main.asp&#xff0c;主文件里推断关闭。防止直接关闭浏览器产生错误
&#39;*************close.asp,同上**********
<%&#64;LANGUAGE&#61;Vbscript%>
<%ON ERROR RESUME NEXT
SET RSCLO&#61;SERVER.CreateObject("ADODB.RECORDSET")
STRCLO&#61;"UPDATE B_MEMBER SET M_ISONLINE&#61;NO,M_ATAREA&#61;&#39;不在线&#39; WHERE M_NAME&#61;&#39;"&SESSION("NAME")&"&#39;"
RSCLO.Open STRCLO,MYCONN
RSCLO.Close
MYCONN.CLOSE
SET RSCLOSE&#61;NOTHING
SET MYCONN&#61;NOTHING
Response.Write err.description
%>
基本是这样的。
版权声明&#xff1a;本文博客原创文章。博客&#xff0c;未经同意&#xff0c;不得转载。