Many people have asked for a copy of the Session Tracker I wrote for CFLib.org. Basically, it allows you to enumerate sessions currently on the system. I also built a simple (and ugly) Flash front end for the tracker. I've uploaded a ziped copy of the code. If you use it, all I ask is that you let me know so that I can link to it. The download can be found here.
(This post is more than 2 years old.)
Session Tracker
Support this Content!
If you like this content, please consider supporting me. You can become a Patron, visit my Amazon wishlist, or buy me a coffee! Any support helps!
Want to get a copy of every new post? Use the form below to sign up for my newsletter.
Archived Comments
Great stuff Ray,
Thanks again for supplying source code. I am learning a lot from your coding:)
Just a thought -- MM may not be too happy that you are distributing the datagrid source code which they are selling under license!
Hilary
http://www.bridel.org/
Oops - didn''t think about that. I removed the FLA from the zip. The SWF is still there, and I''ll see about extracting the AS code from the FLA so I can share that at least.
How should i use the swf file?
i tried to embed it in the page (with no sucess of course).
Thks.
I think that I have tried everything to get this to work and I now know a bit more about structs than I did two days ago, but apparently not enough to get this to output what I want. I can't figure out how to display the complex data elements in a table format.
I added the following to my Application.cfm:
<cfinvoke component="gateway.sessiontracker"
method="registerSession"
pk="#session.urlToken#"
data="#duplicate(session)#">
I added the following to my display page:
<cfinvoke component="gateway.sessiontracker"
method="getSessions"
returnvariable="sessions">
The following works to display all of the data that I need to access:
<cfdump var="#sessions#">
Now how do I display the individual data elements such as HTTP_COOKIE and PATH_INFO from CGI for each user? Also, how do I access the individual values from DATA and the date from STORED?
When I used the following, it displays what appears to be the urltoken from DATA.
<cfoutput>
#Replace("#StructKeyList(sessions)#",",","<br/>","All")#<br/><br/>
</cfoutput>
I then tried the following, but it outputs the same data.
<cfloop collection="#application.sessionTracker#" item="s">
<cfoutput>
#s#<br/>
</cfoutput>
</cfloop>
I inserted cgi.HTTP_COOKIE and cgi.PATH_INFO into the loop, but that displays my information instead of the users.
Any help is greatly appreciated. If this is not the correct forum for this type of support, please let me know.
Thank you,
Brian
This is some old code. I'll answer in general. To get the pieces of a struct, use structKeyList or structKeyArray. This returns the keys of the array. If s is an array, and k is a key, you can get the value by using bracket notation: <cfset value = s[k]>. That's really all there is to it. Just break the struct down to get the values you want.
I believe that my cfinvoke on my output page is correct.
<cfinvoke component="gateway.sessionTracker"
method="getSessions"
returnvariable="sessions">
And my cfloop outputs the keys correctly.
<cfloop collection="#application.sessionTracker#" item="k">
<cfoutput>
Key: #k#<br/>
</cfoutput>
</cfloop>
So, why doesn't this work to display the PATH_INFO for each key?
<cfloop collection="#application.sessionTracker#" item="k">
<cfoutput>
Key: #k#<br/>
Path: #k[sessions.cgi.PATH_INFO]#<br/><br/>
</cfoutput>
</cfloop>
Instead, I get the error "Element CGI.PATH_INFO is undefined in SESSIONS".
Thank you for your assitance.
K is just the struct key name. COnsider array indexes. You can't just do #1#, right? you must do #thearray[1]#. Structs are the say way:
#sessions[k].XXXXX#
It's always the little things, that's what I was missing. Thank you so much for your time and help.
I currently have an existing session tracker in place that is a little simpler that yours, however I was finding that it is adding more sessions than what are truely online.
So, in checking out your CFC I kind of found the same thing:
41
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
69.93.17.28 CFSCHEDULE
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
69.93.17.28 CFSCHEDULE
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
64.158.31.158 CFSCHEDULE
69.93.17.28 CFSCHEDULE
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
24.73.220.34 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Media Center PC 3.0; .NET CLR 1.0.3705)
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
69.93.17.28 CFSCHEDULE
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
216.220.208.237 Mozilla/5.0 (Danger hiptop 2.0; U; AvantGo 3.2)
24.90.100.63 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; {6E28147D-8B3B-A24F-81C8-58BFF15E220A})
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
152.163.100.67 Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
64.158.31.158 CFSCHEDULE
64.180.37.184 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7 (ax)
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
69.93.17.28 CFSCHEDULE
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
64.158.31.158 CFSCHEDULE
216.12.222.108 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
66.249.72.230 Mediapartners-Google/2.1
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
66.249.72.230 Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.h...
In the example above, google bot is swarming be, but you'll see tat it has actually added his IP in as multiple sessions. Im curious why this is.
I actually have both your CFC session tracker and my session tracking in place in my application.cfm. Yours says there are 41 users online, mine says 18.
Thoughts?
Not really sure if I can answer w/o seeing your code as well.