Apache
  Home arrow Apache arrow Page 4 - 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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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 - Active Logins


    (Page 4 of 5 )

    After reading the information stated on the previous pages in this article and understanding the concept of Application and Session objects, I will dwell into keeping track of active Logins on your site. This is slightly trickier as we have to take into account that not every user that surfs your site will Login and not every Login user will manually terminate their Login session by logging out.
    To achieve the above objectives, we will make use of two flag variables called Application("aflgLogin") and Session("sflgLogin") that keeps track of whether the user has logged out manually or the session terminated naturally.
    If you have a Login page running on ASP, chances are that you will be verifying the username and password passed with the values stored in a database. Once that is verified, you would most likely assign Session variables to the Login user to keep track of his username, etc. All we need to add after the user is verified is to add these 2 lines of code once the user is verified.

    'ON THE LOGIN PAGE
     Session("sflgLogin") = True 'Session Flag Variable
     Application("aLogins") = Application("aLogins") + 1

    From there, we know the number of Active Logins by retrieving the value of Application("aLogins") variable and write it to an ASP page.

    On the logout page if the user wants to manually logout, we implement these lines behind the ASP Logout page

    'ON THE LOGOUT PAGE
     If Session("sblnLogin") = True then 'Utilize the Session Flag Variable

    'Decrement the Active Logins accordingly
      Application("aLogins") = Application("aLogins") - 1

    'For Safety measures that the Active Logins cannot fall below ZERO

      If  Application("aLogins") <= 0 then
         Application("aLogins") = 0
      End If
      Session("sblnLogin") = False
      Application.Lock

    'A application Flag variable to be passed to Session_OnEnd when 'Session.Abandon is called next
    'Reason why we pass to an Application Flag Variable is because the 'Session.Abandon method clears all Session variables
    'and runs the Session_OnEnd event of the GLOBAL.ASA file.
    'We need to keep track of whether the user has logged out manually or if the 'session has timed out naturally and we
    'therefore need to keep track of this Application Flag Variable.

     
    Application("ablnLogin") = False
      Application.Unlock
     End If

     Session.Abandon

    On the GLOBAL.ASA file, we need to add these lines in the following events

     Sub Session_OnStart

    'In case this Application variable to keep track of active Logins doesnt exists, 'initialize it to 0
      If IsEmpty(Application("aLogins")) Then
       Application("aLogins") = 0
      End If

     End Sub

     Sub Session_OnEnd

     Application.Lock

    'Application("aflgLogin") = False means User has Destroyed Session, therefore 'reset Application("aflgLogin") then Exit Sub
    'No need to Decrement Application("aLogins") anymore as it had been done so 'at LogOut ASP Page

     If Application("aflgLogin") = False then
        Application("aflgLogin") = ""
        Application.Unlock
        Exit Sub
      End If

    'If Program flowed into here, it means that Application("aflgLogin") is not False 'which means that the session
    'terminated naturally, therefore Decrement Application("aLogins") here.

      Application("aLogins") = Application("aLogins") - 1

    'For Safety measures that the Active Logins cannot fall below ZERO
       If Application("aLogins") <= 0 then
        Application("aiLogins") = 0
       End If
      Application.Unlock

    End Sub

    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-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek