Home arrow Apache arrow Page 3 - ASP: Active Sessions, Active Logins and Total Site Hits
APACHE

ASP: Active Sessions, Active Logins and Total Site Hits


William T explains how to make sure that your site contains a safe and accurate track of genuine page hits.

Author Info:
By: Softwaremaker
Rating: 5 stars5 stars5 stars5 stars5 stars / 59
March 03, 2003
TABLE OF CONTENTS:
  1. · ASP: Active Sessions, Active Logins and Total Site Hits
  2. · Problem Solved
  3. · Writing The Code
  4. · Active Logins
  5. · Conclusion

print this article
SEARCH DEVARTICLES

ASP: Active Sessions, Active Logins and Total Site Hits - Writing The Code
(Page 3 of 5 )

Once you understand the basic concepts of Application and Session objects, you are ready to do wonders with your web application which traditionally takes a lot more coding and programming than your basic standalone ones as the HTTP protocols web applications run on are basically stateless (donít remember anything once they are run).

Letís get our hands dirty by understanding and writing some codes. Because, a Session is instantiated whenever a new browser requests content, a page hit should always be incremented here. To provide for data-persistence when a server shuts down, we will attempt to keep an application count (used throughout the application until the server shuts down) and then write that application count to a text file or a database to keep a "Hard-Copy" record of the total number of site-hits.

Sub Session_OnStart()
  Dim TotalVisits
  Application.Lock
'Application("aHitCounter") is the application variable for keeping track of total number 'of site-hits
'Application("aActiveSess") is the application variable for keeping the number of
active 'sessions of your site the current moment.
'In case this Application variable to keep track of active sessions doesnt exists, 'initialize it to 0
  If IsEmpty(Application("aActiveSess")) Then
   Application("aActiveSess") = 0
  End If
'Read from a stored Text File or a Database that keeps a record of the total no. of site 'hits.
'(We wont cover this topic here) and save the result to a variable called 'TotalVisits
'Increment TotalVisits by 1
  TotalVisits = Clng(TotalVisits)  + 1
'Save this TotalVisits Variable to the Application("aHitCounter") variable
'This application variable can then be used throughout the application, regardless of the 'number of sessions
  Application("aHitCounter") = TotalVisits
'Write Back to the same stored Text File or Database that keeps a record of the total 'no. of site hits the incremented value of the total number of Hits
'To Increment the Active Session Count Whenever a New Session Starts
  Application("aActiveSess") = Application("aActiveSess") + 1
  Application.UnLock
End Sub

After a new user requests any pages from your site, this GLOBAL.ASA file will always run with the this event above. After that, throughout the application, we can access the total number of hits and the active sessions through the Application("aHitCounter") variable and Application("aActiveSess") variable respectively.
Now, we have to take care of the Application("aActiveSess") to make sure that this counter is decremented properly when the user session ends or times out. This is done via the Session_OnEnd Event

Sub Session_OnEnd
'Decrement the Active Session Count After Session Ends
  Application.Lock
  Application("aActiveSess") = Application("aActiveSess") - 1
  Application.UnLock
End Sub


Thats all. When the user session ends or times out, the above event will run and this application("aActiveSess") will be decremented accordingly to better reflect the number of ACTIVE sessions on you site.


blog comments powered by Disqus
APACHE ARTICLES

- Programmatically Manipulating Microsoft Exce...
- Installing PHP under Windows
- Compressing Web Content with mod_gzip and mo...
- Compressing Web Output Using mod_deflate and...
- Setting Up Apache 2.0.45 to Parse PHP Pages
- Custom Error 404 Documents with PHP
- Using Apache and PHP on Mac OS X
- ASP: Active Sessions, Active Logins and Tota...
- Working With Oracle on Windows: Part 1
- The Quick-n-Dirty Guide to Setting Up Apache...
- Installing Apache With SSL: The Complete Gui...
- 7 Powerful .htaccess Customization Tips
- Trap And Get Notified: A Practical Solution ...
- One Way To Use Server Side Includes
- Using ForceType For Nicer Page URLs

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials