[thelist] number of sessions stored on a Coldfusion server - newbie question ?
Gilles Vincent
g_vincent at ixo.fr
Fri Jan 18 08:25:44 CST 2002
Hello,
I've found an excellent tag to track users on
http://cfhub.com/tutorials/online/ (the <cf_trackman> is copied below) ;
however, I would like to get something less complicated : I only need the
number of sessions that are stored on the server :
is there any (non documented ?) server variable that can give it (maybe in
ClusterCats?), or does I always need to store them "manually" in an
application var like in trakman.cfm?
Gilles Vincent
Tip : <cf_trackman> from cfhub.com
<!---
PARAMETERLIST
Action
-ShowAll (Default) Builds a list of all the logged in
users, their page, and their last "Active"
time.
-ShowPage Builds a list of all users "on the same page"
-ShowDir Builds a list of users in "this" folder
(like for a forum maybe?)
Display
-Yes (Default) Uses the "hard coded" display code
-No Stores the information in a "Request" scoped
list: Request.MemberList
--->
<!---===========================================
Code between these sets of horizontal bars
could be cut/pasted into your Application.cfm
file. The application may run a hair quicker.
=============================================--->
<!---Does the Application.Online variable exist yet?--->
<cflock name="TrackMan" type="ReadOnly" timeout="5">
<cfif IsDefined("Application.Online")>
<cfset CreateStructure=FALSE>
<cfelse>
<cfset CreateStructure=TRUE>
</cfif>
</cflock>
<!---Create Application.Online (once only)--->
<cfif CreateStructure>
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Application.Online=StructNew()>
</cflock>
</cfif>
<!---Remove "old" users ("TimeOut Minutes")--->
<!---First build a list of users "older" than "TimeOut"--->
<cfset TimeOut=30>
<cfset UserList="">
<cflock name="TrackMan" type="ReadOnly" timeout="10">
<cfloop collection="#Application.Online#" item="ThisUser">
<cfif DateDiff("n",Application.Online[ThisUser][1],now()) GTE TimeOut>
<cfset UserList=ListAppend(UserList,ThisUser)>
</cfif>
</cfloop>
</cflock>
<!---Then delete "old" users--->
<cfloop list="#UserList#" index="ThisUser">
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Temp=StructDelete(Application.Online,ThisUser)>
</cflock>
</cfloop>
<!---Build "This" Members "Info" Array--->
<cfscript>
Members=ArrayNew(1);
Members[1]=now();
Members[2]=CGI.CF_Template_Path;
</cfscript>
<!---add Members "Info" to "Online" Structure--->
<cflock name="TrackMan" type="Exclusive" timeout="5">
<cfset Temp=StructInsert(Application.Online,Session.Admin,Members,TRUE)>
</cflock>
<!---===========================================
If you like, paste all the preceding code into your
Application.cfm file.
=============================================--->
<!---The tag parameters--->
<cfparam name="Attributes.Action" default="ShowAll">
<cfparam name="Attributes.Display" default="No">
<!---The main "Switch"--->
<cfswitch Expression="#Attributes.Action#">
<!---Build List of Users on the same page--->
<cfcase value="ShowPage">
<cfset Request.MemberList="">
<cflock name="TrackMan" type="ReadOnly" timeout="10">
<cfloop collection="#Application.Online#" item="ThisUser">
<cfif Application.Online[ThisUser][2] IS CGI.CF_Template_Path>
<cfset Request.MemberList=ListAppend(Request.MemberList,ThisUser)>
</cfif>
</cfloop>
</cflock>
</cfcase>
<!---Build List of Users in the same folder--->
<cfcase value="ShowDir">
<cfset Request.MemberList="">
<cflock name="TrackMan" type="ReadOnly" timeout="10">
<cfloop collection="#Application.Online#" item="ThisUser">
<cfif GetDirectoryFromPath(Application.Online[ThisUser][2])
IS
GetDirectoryFromPath(CGI.CF_Template_Path)>
<cfset Request.MemberList=ListAppend(Request.MemberList,ThisUser)>
</cfif>
</cfloop>
</cflock>
</cfcase>
<!---Default (all logged in users)--->
<cfdefaultcase>
<cfset Request.MemberList="">
<cflock name="TrackMan" type="ReadOnly" timeout="10">
<cfloop collection="#Application.Online#" item="ThisUser">
<cfset Request.MemberList=ListAppend(Request.MemberList,ThisUser)>
</cfloop>
</cflock>
</cfdefaultcase>
</cfswitch>
<!---Display the information if Display="Yes"
Obviously a little table formatting would go a
long way here... This table is a little "simple".
Some pretty colours perhaps?--->
<cfif Attributes.Display is "Yes">
<table border=2 rules="All">
<cflock name="TrackMan" type="ReadOnly" timeout="20">
<cfloop list="#Request.MemberList#" index="ThisUser">
<cfoutput>
<tr><td>
<b>#ThisUser#</b>
is currently viewing page
<b>#Application.Online[ThisUser][2]#</b>
and has been inactive since
<b>#TimeFormat(Application.Online[ThisUser][1])#</b>
<b>#DateFormat(Application.Online[ThisUser][1])#</b>
</td></tr>
</cfoutput>
</cfloop>
</cflock>
</table>
</cfif>
More information about the thelist
mailing list