Archive for the ‘ASP’ Category

ASP: Online Users Counter

Monday, August 10th, 2009

This popular script is found in almost all sites in ASP, used to count visitors assets (present at the time), is on our website.

The code should be used in the file Global.asa. Must not be enclosed in <% and%> must be unique and that has within it. (Well, not unique, but playing with Global.asa not recommend it).

Here’s the code that goes into the Global.asa

<script language=vbscript runat=server> 

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

Sub Application_OnEnd
End Sub 

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

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

</script>

And to show the information which the Global.asa, or to show active users as I did in my example, they should put the following on the page displaying the data:

<P>There are currently <%=Application("Active")%> user's on our site</P>

Happy Programming!!! ;)