Online Statistics Code Application

Source: Internet
Author: User

First, set the global. Asa file as follows:

The following content is the program code
  1. <Script language = "VBScript" runat = "server">
  2. Sub application_onstart
  3. Application ("activeusers") = 0 // Initial Value
  4. End sub
  5. Sub session_onstart
  6. Session. Timeout = 20 // The time when the non-active user is deleted
  7. Session ("START") = now
  8. Application. Lock // lock the application variable
  9. Application ("activeusers") = Application
  10. ("Activeusers") + 1 // statistics
  11. Application. Unlock // unlock
  12. End sub
  13. Sub session_onend
  14. Application. Lock
  15. Application ("activeusers") = Application
  16. ("Activeusers")-1 // Delete unactive users or quit users
  17. Application. Unlock
  18. End sub
  19. </SCRIPT>

Page showing the number of online users

The following content is the program code
  1. <% @ Language = VBScript %>
  2. online user
  3. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.