Codefixer - ASP tutorials, resources and software
ASP.NET Hosting with US & UK Data Centers!
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Monday 6 October
MembersPro PayPal - ASP Membership software

New MS SQL 2008 Available – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Getting the number of Active Users on your Website with ASP

This is a neat little script that will tell you how many active users you have on your site. It can be somewhat disheartening if you don't get any though!

What is required is somewhere to store the number of people which will be a variable i.e. amount of people on your site will vary. You will need to create a separate file in which to store this variable. For this purpose we use the global.asa. I am not going to go into too much detail about this file other than to tell you to cut and paste the code below into the file called global.asa

<script language="vbscript" runat="server">

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

Sub Application_OnEnd
'no code is needed here
End Sub


Sub Session_OnStart
Session.Timeout=20
Session("Start")=Now
Application.Lock
Application("Active")=Application("Active")+1
'this adds 1 to the number of active users when a new user hits
Application.unlock
End Sub

Sub Session_OnEnd
Application.Lock
Application("Active")=Application("Active")-1
'this subtracts 1 from the number of active users when a new user leaves
Application.unlock
End Sub

</script>

The above is your global.asa file, below the code that you should cut and paste into another file. You can call the file whatever you like, though I'll call it 'active_users.asp'

<html>
<head>
<title>active users</title>
</head>

<body>
You are one of <%= Application("Active")%> current users.
</body>
</html>

Upload both files on to the net making sure that the 'global.asa' is in the root directory. Run the file 'active_users.asp' and you'll discover how many active users you have.

LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software