Home arrow Apache arrow Page 4 - 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 - 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


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