When browsing the web, you can often see the number of "people on the current site is xxx" online count. How to use ASP to do one? First of all, the analysis of its practice, in general, these online statistics refers to the number of visitors in a period of time statistics. For example (within 5 minutes, 10 minutes) and the length of this time is set by the designer.
Total number of visitors with different IP in this time period, we can draw the current number of online, but there is a precise problem to be solved, as to how to accurately statistics, that is, the different ways of doing things, such as the use of automatically submitted pages, a period of time to read cookies and so on, And in the ASP, there is a better technique, is to use the session object to statistics, here to introduce the Gobal.asa this file, this is a very important document, please look at 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 and makes a request to the Web server) then, if the first user after the server starts, both the Application_onstard and Session_OnStart events occur, and then the If another user makes a request, it only occurs Session_OnStart this event, and the lifetime of the session is how long, can be set, session.timeout=x (minutes)
Well, with this very good method, we can accurately count the number of people online, and the total number is saved with a application variable, when the first session starts at Application_ A statement that empties the counter in the Onstard event application ("online") = 0, and then, in the Session_OnStart event, place a statement to increase the number of people online application ("online") = Application ("online") +1, and in the Session_OnEnd event to put a reduction in the number of online statements, so that the count value minus one.
In this way, the document is replaced by 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, make up a program that displays graphic numbers, displaying the number of people online on the specified page. So we can get the numbers.
*online.asp
<% @language = "VBScript"%>
<%
Tmp=application ("online")
TMP=CSTR (TMP)
Dim disp (20)
Dim images (20)
Dbbits=len (TMP)
For i= 1 to Dbbits
Disp (I) =left (Right (tmp,i), I-(I-1))
Next
For I=dbbits to 1 step-1
Images (i) = " "
Response.Write "Document.Write (" &images (I) & ");"
Next
%>
The above procedure is very simple, here does not make the analysis, invites everybody to read by oneself. Use a script statement to refer to the Online.asp file on the page that invokes the online statistics to display the graphical statistics device.
<script language= "JavaScript" src= "http://xxxx.com.cn/online.asp" > </script>
Now it's OK, remember the gist, you have to put Gobal.asa on the right Web application root directory, and it is best to create a new Web application for this statistic alone, not to mess with other programs, otherwise the data is inaccurate, and it is easy to modify the program to multi-user online statistics. This can provide online statistical services, how to achieve please let us think about it ....