Design the online website count statistics program with ASP

Source: Internet
Author: User
When browsing the web page, you can often see that the number of online users on the current website is XXX. How can I use ASP for one? First, let's analyze its practice. In general, these online statistics refer to the number of visitors in a period of time. For example, the length of the time (within 5 minutes, within 10 minutes) is set by the designer.
In this period, the total number of visitors from different IP addresses can be obtained. However, there is a precise problem to be solved. How can we accurately calculate the number of online visitors, that is to say, we have different practices. For example, we can use an automatically submitted page to read COOKIES over a period of time. In ASP, there is a better technique, the session object is used for statistics. Here we will introduce gobal. the asa file is a very important file. Please check its structure.
<Script language = "VBScript" RUNAT = "Server">
Sub Session_OnStart
End Sub
Sub Session_OnEnd
End Sub
Sub Application_OnStard
End Sub
Sub Application_OnEnd
End Sub </SCRIPT>
When a session occurs (the user browses the Web page and sends a request to the Web server), the Application_OnStard and Session_OnStart events will occur for the first user after the server starts, then, if another user sends a request, only the Session_OnStart event will occur. The session duration can be set. timeout = X (minutes)
Well, with this very useful method, we can accurately calculate the number of online users, and the total number of people is saved using an application variable. When the first session starts, in the Application_OnStard event, place a statement application ("online") = 0 to clear the counter. Then, in the Session_OnStart event, place a statement application ("online") that increases the number of online users ") = application ("online") + 1, and put a statement to reduce the number of online users in the Session_OnEnd event, so that the count value is reduced by one.
Zmbbs = 1;

In this way, the file is changed to the following:
<Script language = "VBScript" RUNAT = "Server">
Sub Session_OnStart
Application ("online") = application ("online") + 1
End Sub
Sub Session_OnEnd
Application ("online") = application ("online")-1
End Sub
Sub Application_OnStard
Application ("online") = 0
End Sub
Sub Application_OnEnd
Application ("online") = 0
End Sub </SCRIPT>
Next, compile a program to display the number of online users on a specified page. In this way, the number of people can be obtained.
Related Article

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.