|
This code snippet shows how to show how
many active users there are on your site , this is quite
widely used on the internet.
using your favorite text editor create
the file global.asa and enter the code below
<SCRIPT LANGUAGE=VBScript
RUNAT = Server>
Sub Application_OnStart
Application("visits")=0
Application("Active")=0
End Sub
Sub Application_OnEnd End
SubSub Session_OnStart
'set timeout to 20 mins
Session.Timeout = 20
Session("Start") = Now
'increase count by 1
Application.lock
Application("visits") = Application("visits")
+ 1
intTotal_visitors = Application("visits")
Application.unlock
Session("VisitorID") = intTotal_visitors
Application.lock
Application("Active") = Application("Active")
+ 1
Application.unlock
End Sub Sub
Session_OnEnd
'decrease by 1 when session ends
Application.lock
Application("Active") = Application("Active")
- 1
Application.unlock
End Sub </script>
Now add the following to a page to count the
active users
<b><%= Session("VisitorID")%></b>
visit(s) <b><%= Application("Active")%></b>
visitor online
If you look below you can see this in action
|