Search DaTutorials:  
HOME
ASP Tutorials
Introduction
Reference
   Building ASP Pages
   Built-in Objects
Tutorials

Display the Number of Users Online

Description:


Learn how to use global.asa to display the number of users visiting your site using ASP and VB Script.

The code contains two parts. The first part is part of the "global.asa" file which is to be placed directly under your root directory. The second part is the code to display the actual number of people online.

Code:

Place this code in your global.asa :


Sub Application_OnStart
    Application("UsersOnline") = 0
End Sub

Sub Application_OnEnd
    '---nothing here

End Sub

Sub Session_OnStart
    Session.Timeout = 20
    '---lock Application variable before updating

    Application.Lock
        Application("UsersOnline") = Application("UsersOnline") + 1
    Application.Unlock
End Sub

Sub Session_OnEnd
    Application.Lock
    Application("UsersOnline") = Application("UsersOnline") - 1
    Application.Unlock
End Sub

Place this code in the page where you want to display the number of users currently online.

<html> <body>
Currently there are <%=Application("UsersOnline")%> users online.
</body> </html>

Keywords:

ASP: global.asa, Application, Application_OnStart, Application_OnEnd, Session_OnStart, Session_OnEnd

VBScript: Sub


     Debt Help | Loans | Problem Mortgage | Personal Car Finance | Free Advertising
Home     Link To Us     Ad With Us     Contact Us     Tell A Friend     Affiliates     Blog     MsOfficeHelp