First, set the global. Asa file as follows:
The following content is the program code
-
- <Script language = "VBScript" runat = "server">
-
- Sub application_onstart
-
- Application ("activeusers") = 0 // Initial Value
-
- End sub
-
- Sub session_onstart
-
- Session. Timeout = 20 // The time when the non-active user is deleted
-
- Session ("START") = now
- Application. Lock // lock the application variable
-
- Application ("activeusers") = Application
-
- ("Activeusers") + 1 // statistics
-
- Application. Unlock // unlock
-
- End sub
-
- Sub session_onend
-
- Application. Lock
-
- Application ("activeusers") = Application
- ("Activeusers")-1 // Delete unactive users or quit users
-
- Application. Unlock
-
- End sub
-
- </SCRIPT>
|
|
Page showing the number of online users
The following content is the program code
- <% @ Language = VBScript %>
-
-
- online user
-
-
- currently <% = Application (" activeusers ") %> person online
-
-
|
|
the most common method is to use a session, but the disadvantage is that it cannot instantly reflect online conditions (with timeout) and occupy server resources (if 100 people are online, there will be 100 sessions, think about 8); the last time (as if it had been a long time), we introduced a method to use application + cookies. However, the implementation method is cumbersome and we need to set up a hidden self-Refresh page.
This method avoids the above disadvantages. After practice, the effect is good (example: www. Atersoft. COM/BBS), as follows:
assume index. Htm is a framework webpage, which contains three frameworks: Id = left, id = top, and Id = bottom
1. Make a statistics page named usernum. ASP
is collecting statistics...
<%
User = request. querystring ("user")
If user = 0 then 'number of people leaving-1
application. lock
application ("num") = Application ("num")-1
application. unlock
response. write " "
elseif user = 1 then' + 1
application. lock
application ("num") = Application ("num") + 1
application. unlock
end if
%>
2. For example, index on the Framework page. Htm) embedded usernum. ASP
...
3. On the page for displaying the number of people (shown on left)
<% = Application ("num ") %>
4. Set the page for updating data (such as bottom)
function TJ () {
top. left. num. innerhtml = <% = Application ("num") % >;< BR >}< br>
finished, this is just an example. The specific application can be flexible. In addition, why do we need a window when we leave. Open usernum. What about ASP? Because if it is also placed in ifrme, the window is closed too fast, usernum. ASP pages are closed when loading is too late. The number of users cannot be reduced.