<cflock scope="session" throwontimeout="no" timeout="10">
<cfscript>
function getSessions(appName)
{
var tracker = createObject("java","coldfusion.runtime.SessionTracker");
return tracker.getSessionCollection(appName);
}
</cfscript>
<cfset nSessions = 0>
<cfset nLoggedIn = 0>
<cfset sessions = getSessions(application.applicationName)>
<cfset nSessions = structCount(sessions)>
<cfloop item="s" collection="#sessions#">
<cftry>
<cfif structKeyExists(sessions[s].msg,"EMAIL")>
<cfset nLoggedIn = nLoggedIn + 1>
</cfif>
<cfcatch></cfcatch>
</cftry>
</cfloop>
</cflock>
the nSessions holds a count of ALL sessions and nLoggedIn holds a count of all users logged in. This works well enough. The nLoggedIn value is always accurate if users actually use the logout buttons, else it has to time out when they leave.
The nSessions is usually NOT accurate since it has to time out for everyone. I've tried a couple different things for killing the session or dereferencing it when the browser is closed but no luck.
In the MM forums I read this would do it if i dropped it in the application.cfm
<cflock scope="Session" type="Exclusive" timeout="10">
<cfset StructClear(Session)>
</cflock>
but it seems to clear the session on evry page load or refresh
I also tried this in the application.cfm as the livedocs suggested
<cflock timeout="180" scope="session" type="readonly">
<cfcookie name="CFID" value="#Session.CFID#">
<cfcookie name="CFTOKEN" value="#Session.CFTOKEN#">
</cflock>
but this was even worse, not only did the session not die when the browser was closed, it started a completley NEW session when the browser came back (weird)
----- Original Message -----
From: Raymond Camden
To: CF-Talk
Sent: Monday, August 09, 2004 8:44 AM
Subject: Re: Count logged in user sessions
There are a few different ways to do this. There is a ServiceFactory
method that will help. This article,
http://www.findarticles.com/p/articles/mi_m0MLU/is_10_5/ai_109039749,
written by myself, shows code that Sam Neff wrote. You can also do
tracking in application.cfm by doing (pseudo-code)
param application.sessions
application.sessions[session.urltoken] = now();
What this does is create one record per session in an application
struct. It uses the current time as the value. When you count the
sessions, you simply remove any session who has a value more then your
timeout, normally 20 minutes. This will give you the current number of
sessions.
On Sat, 7 Aug 2004 18:52:50 -0400, Ewok <[EMAIL PROTECTED]> wrote:
> Doesn't look like this came through the first time... if its double posted you can hang me by my ... ummm...parts
>
> This has got to be possible. Seems like I remember the question being asked before but can't seem to word it right in the archives to get any results. Anyone know a link or a solution?
>
> I am using sessions to log people in and keep them logged in. There must be a way to count active sessions right? I just need a number, I don't plan to pull specific data about users who are logged in...... although it would be nice to know that too : )
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

