Posted in ColdFusion | Posted on 12-20-2006 | 2,051 views
This is just a quick follow up to yesterday's post on the session logging demo I showed.
First - David Crowther mentioned that I could cut two database queries down to one by just doing the insert in the onSessionEnd method. I don't think this is such a big deal - but it does make things a bit simpler so I made the change.
Next - Geoff made a good point. He asked if I was sure session.urltoken was unique over system reboots. Using J2EE sessions I'm pretty darn sure it is - but why take chances when ColdFusion makes it so easy to create a unique ID with createUUID()?
For these new suggestions I added three new session variables (id, entrypage, and entrytime), and you can find the code in the Download.
I also wanted to mention something else. When creating your reports, it may be useful to create a simple function to show nicer names for the URLs. So for example, your code could translate /company/about.cfm to "About our Company". It could translate /company/news.cfm?id=45 to "News: Adobe buys Microsoft". This will create reports that are much easier to read.
Thanks to David and Geoff for the good ideas!


Another interesting side effect of doing this tracking is the ability to add a field to capture IP address and maybe a message or a utility key field. At that point you can also use the same tracking for some ancillary security work and reporting. An example would be to use this information to drive a 3 bad logins and lock them out for x minutes etc.
Thanks Ray.
DK - you might not want to do that. FOr example, imagine a site that lets you do some stuff not logged in, some stuff logged in. Just because you logout doesn't mean you leave. You may browse some more. If I wanted to care JUST about people logged in, I wouldn't use onSessionStart/End at all. It is too ripe for confusion.
= =
yeah sorry, I was thinking of how one of my clients implemented it, which was tracking logged in user trends only. my bad :D
<cffunction name="onRequest" returnType="void">
<cfargument name="thePage" type="string" required="true">
<cfinclude template="#arguments.thePage#">
</cffunction>
I didn't see it in the first version...
http://livedocs.macromedia.com/coldfusion/7/htmldo...
But anyway - if you want to do a set of things on logout and have it be the _same_ as a 'real' session timeout, make a new method, and have onRequestStart note the logout and call the new method, and have onSessionEnd do the same. Don't forget though that you can't output or DIRECTLY use session.foo in onSesionEnd, and that would apply to this new method you can as well.
[Add Comment] [Subscribe to Comments]