User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 332,778 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,830 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Apr 9th, 2005
Views: 3,932
This is a neat little script that will tell you how many active users
you have on your site. You do need a webhost that supports the
global.asa file! Most free hosts dont.

Code From: http://www.iportalx.net
Last edited : Jan 2nd, 2007.
asp Syntax | 5 stars
  1. First lets create the global.asa file that counts the active users.
  2. Again, your host must support global.asa files or this will not work!
  3.  
  4. [code]
  5. <script language="vbscript" runat="server">
  6.  
  7. Sub Application_OnStart
  8. 'Set the active users to zero
  9. Application("ActiveUsers") = 0
  10. End Sub
  11.  
  12. Sub Application_OnEnd
  13. 'no code is needed here
  14. End Sub
  15.  
  16. Sub Session_OnStart
  17. Session.Timeout = 5
  18. Session("Start") = Now
  19. Application.Lock
  20.  
  21. 'Add one to the active users when the person first visits
  22. Application("ActiveUsers") = Application("ActiveUsers") + 1
  23.  
  24. 'this adds 1 to the number of active users when a new user hits
  25. Application.unlock
  26. End Sub
  27.  
  28. Sub Session_OnEnd
  29. Application.Lock
  30.  
  31. 'Subtract one after the user leaves your website
  32. Application("ActiveUsers") = Application("ActiveUsers") - 1
  33.  
  34. 'this subtracts 1 from the number of active users when a new user leaves
  35. Application.unlock
  36. End Sub
  37.  
  38. </SCRIPT>
  39. [/code]
  40.  
  41. Now that the global.asa file is created you can include the following any where on your ASP pages.
  42.  
  43. [code]
  44. You are one of <b><% = Application("ActiveUsers") %></b> current users
  45. [/code]
  46.  
  47. Note: You do not need to include the global.asa file!
  48.  
  49. Now upload the global.asa file to the ROOT directory of your website
  50. (that would be the very first directory that your website looks in when
  51. you visit you websites URL).
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 9:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC