Active Users ASP Script - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Scripts

ACTIVE USERS

One popular web statistic that is fun to track is how many users are currently using your website.

The first thing you need to do is create a global.asa page with the code below:

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
' Set our user count to 0 when we start the server
Application("ActiveUsers") = 0
End Sub
Sub Session_OnStart
' Change Session Timeout to 20 minutes (if you need to)
Session.Timeout = 20
' Set a Session Start Time
' This is only important to assure we start a session
Session("Start") = Now
' Increase the active visitors count when we start the session
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
' Decrease the active visitors count when the session ends.
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
End Sub
</SCRIPT>

Next, we create a displaystats.asp page and enter the code as seen below:

<HTML><HEAD>
<TITLE>ASP Web Pro</TITLE>
</HEAD>

<BODY>

<P>
There are currently <% = Application("ActiveUsers") %> users on this website.
</P>

</BODY>
</HTML>

Now, you have a count of how many Active Users are on your website.

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
06 July 2008