Use ASP to display the current number of online users

Source: Internet
Author: User
Tags http request
Currently, website creation has become a fashion, and various websites have sprung up. It is made with CGI, ASP, and PHP. Some websites can calculate the current number of online users, for example, "There are currently 32 online users ". Then, how can I display the current number of online users on a website created using ASP?
    
When the web pages created using ASP are stored in the base point Directory of the WWW server and the WWW server is started, the server reads the Global address in the base point directory whenever an HTTP request is sent to the ASP file. asa file. To count the number of online users of the website, we can include the following code in the Global. asa file:
    
<Script language = "VBScript" RUNAT = "Server">
Sub Application_OnStart
    
'When the server is enabled, set the user counter to 0.
Application ("ActiveUsers") = 0
End Sub
Sub Session_OnStart
    
'The validity period of the Session object is set to 20 minutes (or longer, but the longer the Session object is, the more resources the server occupies, because the server does not accept the validity period of less than 20 minutes, therefore, setting the 'validity period less than 20 minutes is invalid)
Session. Timeout = 20
    
'Add 1 to the user counter when starting a Session
Application. Lock
Application ("ActiveUsers") = Application ("ActiveUsers") + 1
Application. UnLock
End Sub
Sub Session_OnEnd
    
'When a Session ends, the user counter minus 1
Application. Lock
Application ("ActiveUsers") = Application ("ActiveUsers")-1
Application. UnLock
End Sub
</SCRIPT>
    
In this way, the number of online users of the website is counted. We can use the following ASP page (js. asp) to display it: jsh. asp:
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.