Apache
  Home arrow Apache arrow Page 3 - ASP: Active Sessions, Active Logins and To...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

ASP: Active Sessions, Active Logins and Total Site Hits
By: Softwaremaker
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2003-03-03

    Table of Contents:
  • ASP: Active Sessions, Active Logins and Total Site Hits
  • Problem Solved
  • Writing The Code
  • Active Logins
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More Apache Articles
    More By Softwaremaker


     

    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







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway