Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count of active sessions

Status
Not open for further replies.

bigKev

IS-IT--Management
Mar 16, 2001
19
0
0
AU
Quite simple, I have a count of users on-line in the password protected area of my site, but can I, using the session management or otherwise, display a reasonably accurate total of the number of people using the public site at any time ...

eg to display "You are 1 of 1234 candidates currently looking for work on this site" ????
 
I answered this type of question on another site and here's my answer. What you're wanting to do isn't simple but what I outlined should work for you. If anyone has a better way, I'd love to hear.

GJ
-----------------------------------------------------

To determine the number of current sessions in Cold Fusion, a simple tracking mechanism can be developed
similar to some of the previous comments. Just create a global variable that will hold the number of
current sessions. Since this number needs to be decremented when the visitor leaves the site and there
is no way to determine this, you will need to schedule a clean-up script to run every few minutes and
reset the count to 0. The quicker you run this script, the more accurate your count will be. I don't
see any problem running it every minute if you like but every five minutes would probably be acceptable.

You will also need to sync up the sessions to make sure that each visitor's session updates the count
once during each refresh period. For example, assume a 5 minute refresh. If the count is reset at
12:00 and a visitor comes to the site at 12:01, the count will be 1. If the next reset occurs at 12:05,
you want to make sure the visitor doesn't update the count again for another 5 minutes. To do this,
create a session variable to keep track of the last time the visitor updated the master count (updTime
for example). On each page request, check to see if the current time is more than 5 minutes past updTime.
If it is, update the master count and set updTime to the current time. Once the counter mechanism
is in place, it's a simple task to write a script to check and display the master count.

All in all, it's not perfect but will give you a reasonable current session count. The accuracy will
improve as traffic increases and as the refresh time is decreased. You can modify this to work only
on specific pages to get the count for a specific group or put it in the application.cfm file to get
numbers for the whole site.

To do this without cookies requires that all of your pages be CF scripts and that you pass the cfid
& cftoken to each page as url variables. If you do this, you will have a high degree of session accuracy
even if cookies are turned off.

An alternative would be to write a custom sniffer application in C++, Java, etc.. and watch for url
requests coming across the network. This would give you a much higher level of accuracy but is not
a realistic solution in most cases.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top