Global.asa里可以这样写:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_onStart '初始值为0
Application("OnLine") = 0
End Sub
Sub Session_onStart '一个用户访问进行记数加1
Application.Lock
Application("OnLine") = Application("OnLine") + 1
Application.Unlock
End Sub
Sub Session_OnEnd '一个用户进程的结束,记数减1 (P.S.如果没有该事件程序,则执行的就是页面访问程序了。)
Application.Lock
Application("OnLine") = Application("OnLine") - 1
Application.Unlock
End Sub
</SCRIPT>
<!--#include file="chksql.asp" -->
<%
ip=request.servervariables("http_x_forwarded_for")
if ip="" then
ip=request.servervariables("remote_addr")
end if
set rs=server.CreateObject("adodb.recordset")
ss=chksql(session.SessionID)
uname=chksql(request.Cookies("username"))
ere=chksql(request.Cookies("eremite"))
sql="select * from online where ip='"&ip&"'and (sessionid="&ss&" or username='"&uname&"')"
rs.open sql,conn,3,3
if rs.eof and rs.bof then
rs.addnew
rs("sessionid")=ss
rs("username")=uname
rs("eremite")=ere
rs("ip")=ip
rs("acturl")=cstr(Request.ServerVariables("script_name"))
rs("lasttime")=now
else
rs("acturl")=cstr(Request.ServerVariables("script_name"))
rs("lasttime")=now
end if
rs.update
rs.close
conn.execute("delete from online where datediff('s', lasttime, now())>7200")
%>