本文共 1960 字,大约阅读时间需要 6 分钟。
Application变量说明
Application变量同Session变量相类,所不同的是Application变量的值对所有的用户都是相同的,Session变量对每位用户都是不同的. 系统为每位用户建立他们的 Session变量的实例. 在服务器启动时,系统建立唯一的Application变量. 希望这些概念对理解下面的代码有利.
文件: Global.asa
' Here you want to define the time that the user ' will be valid as on-line. (If no activity occurs ' for x minutes, then log the user off (erase his ' session variable instances)) Session.Timeout = 3 ' The .Lock method locks the Application variable so that ' you can work on it. If you don't lock it there won't be ' any changes on the variable "WhosOn" Application.Lock
' Start the variable at 0, Application("WhosOn") = 0
' You now need to unlock the application Application.UnLock End Sub Sub Session_OnStart ' Sub Session_OnStart is the procedure that works ' everytime a new user enters in your page
' Here is the place where you increment the number ' of users on your page (don't forget to Lock/Unlock ' your Application variable!) :) Application.Lock Application("WhosOn") = Application("WhosOn") + 1 Application.UnLock End Sub Sub Session_OnEnd ' Sub Session_OnEnd is the procedure that works ' everytime a user quits the page, this is defined n ' minutes after he quits. ' This n minutes are defined by the Session:Timeout in ' Sub Application_OnStart ' So... when a user quits there will be one less user, so we ' decrement one on the "WhosOn" variable (don't ' forget to Lock/Unlock your application variable! :) Application.Lock Application("WhosOn") = Application("WhosOn") - 1 Application.UnLock End Sub 文件: main.asp 下面的代码将实时地显示给你的站点的每位访客有多少用户在线:response.write "Are Now " & Application("WhosOn") & " users at this page." %>
编程快乐!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124702/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10294527/viewspace-124702/