日期:2014-05-16 浏览次数:21063 次
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
'当服务器开启时,设置在线用户计数器为0
Application("ActiveUsers") = 0
'设置每天访问量为0
Application("EveryDayUsers") = 0
'访问的时间为
Application("RecordDate") = "2009-01-01"
End Sub
Sub Session_OnStart
'设置Session对象的有效时间为20分钟(也可以更长,但是越长对服务器的资源'占用越多,因为服务器不接受少于20分钟的有效时间,所以设置少于20分钟的'有效时间是无效的)
'Session.Timeout = 30
' 当开始一个Session时在线用户计数器加1
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
'每天的访问量加1
Response.write Application("RecordDate") &"|" &Date()
if Application("RecordDate") <> Date() Then
Response.write "111"
Application.Lock
Application("RecordDate") = Date()
Application("EveryDayUsers") = 1
Application.UnLock
Response.write "<br>"& Application("RecordDate")
else
Application.Lock
Application("EveryDayUsers") = Application("EveryDayUsers")+1
Application.UnLock
end if
'统计总访问量
CountFile=Server.MapPath("/txtcounter.txt")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.OpenTextFile(CountFile,1,FALSE,FALSE)
counter=Out.ReadLine
Out.Close
SET FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.CreateTextFile(CountFile,TRUE,FALSE)
Application.lock
counter= counter + 1
Application("TotalUsers") = counter
Out.WriteLine(counter)
Application.unlock
Out.Close
End Sub
Sub Session_OnEnd
'当结束一个Session时用户计数器减1
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
End Sub
</SCRIPT>