Show | online | online | Number of people online now, the site has become a fashion, a variety of sites have sprung up. Useful CGI made, useful ASP made, but also useful PHP production, and so on. Some websites can count the current number of online people, such as: "There are currently 32 online." So how does the Web site that is made with ASP display the current number of people online?
When the Web pages made with ASP are stored with the basic point directory of the WWW server and the WWW server starts, whenever there is an HTTP request to the ASP file, the server will read the Global.asa file in the base-point directory. To count the number of online sites, we can include the following code in the Global.asa file:
<script language= "VBScript" runat= "Server" >
Sub Application_OnStart
' Set the user counter to 0 when the server is turned on
Application ("activeusers") = 0
End Sub
Sub Session_OnStart
' Set the Session object to a valid time of 20 minutes (or longer, but the longer the server's resources are consumed, because the server does not accept less than 20 minutes of valid time, so setting less than 20 minutes of ' valid time is invalid ')
Session.Timeout = 20
' When starting a session, the user counter plus 1
Application.Lock
Application ("activeusers") = Application ("activeusers") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
' User counter minus 1 when ending a session
Application.Lock
Application ("activeusers") = Application ("Activeusers")-1
Application.UnLock
End Sub
</SCRIPT>
In this way, the online number of the site is counted, we can use the following an ASP page (js.asp) to display it: jsh.asp:
<%@ Language=vbscript%>
<HTML>
<HEAD>
<TITLE> Statistics Online Number </TITLE>
</HEAD>
<BODY>
<b><font color= "#CC0000" > Current online <%= application ("Activeusers")%> people </FONT></B>
</BODY>
</HTML>
The above code was debugged and passed under Win NT (IIS 4.0).