![]() |
|
|
Published: Sunday, June 13, 1999 How Many People Are on your Site Right Now?
I think this one is really easy, and even if you never used global.asa don't worry, just
put the one I have at this page for download at the root of your page (e.g.
www.yourpage.com/global.asa).
If you are unfamiliar with global.asa, be sure to also check out
this article on Global.asa.
Now all you need is to keep track of a counter as each new user enters
your page. You'll also need to decrement your counter when someone leaves,
and have code to display the current count. File: Global.asa <SCRIPT LANGUAGE="VBScript" RUNAT="Server"> Sub Application_OnStart
' Sub Application_OnStart is the procedure that fires
' everytime your server starts up.
' Here you want to define the time that the user
' will be valid as on-line. (If no activity occurs
' for x minutes, then log the user off (erase his
' session variable instances))
Session.Timeout = 3
' The .Lock method locks the Application variable so that
' you can work on it. If you don't lock it there won't be
' any changes on the variable "WhosOn"
Application.Lock
' Start the variable at 0,
Application("WhosOn") = 0
' You now need to unlock the application
Application.UnLock
End Sub
Sub Session_OnStart
' Sub Session_OnStart is the procedure that works
' everytime a new user enters in your page
' Here is the place where you increment the number
' of users on your page (don't forget to Lock/Unlock
' your Application variable!) :)
Application.Lock
Application("WhosOn") = Application("WhosOn") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
' Sub Session_OnEnd is the procedure that works
' everytime a user quits the page, this is defined n
' minutes after he quits.
' This n minutes are defined by the Session:Timeout in
'
</SCRIPT>
File: main.asp We'll,... after lots of research I made this code that show the users that are seeing your page on real-time by getting the info from the application variable... <%
response.write "Are Now " & Application("WhosOn") & " users at this page."
%>
Happy Programming! João Vieira BIO: (email me!)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||