Displaying current online numbers with ASP

Source: Internet
Author: User
Tags count http request valid
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).



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.