Remember client scope. Ahhh yes, ye olde client scope. I remember 7 years ago, when I stopped using client scope all together, I missed having variables such as client.lastVisit, client.hitCount, and client.TimeCreated. There are several solutions to mimic the first two, but I never found anything that I felt really truly suited me. I've had enhancement requests with Adobe since CF7 days to add this functionality to the session scope, and I remember once when Ray and I barraged Macromedia about it.
Lately I started playing with a java taglib that provided some of the functionality I was looking for. More info on the taglib can be found @ http://www.servletsuite.com/servlets/sessinfotag.htm. Immediately I saw its uses.
Again, I've only quickly played with this, but it looks promising. I created a directory off the webroot. I downloaded the JAR and TLD file there. (Probably don't need the TLD file.)
The JAR exposes 4 methods:
- sessionUsedTime: Which answers the question: How long has it been since this session was created? From that you could also extract exact time it was created similar to client.timeCreated.
- sessionInactiveTime: ** THE MOST USEFUL! ** Which answer the question: How long since the session was touched? Similar to client.lastVisit.
- isNewSession: Self explanatory.
- isNotNewSession: Self explanatory.
Let's explore numbers 1 and 2 above. Take a look at this code.
<cfimport taglib="sessinfotag.jar" prefix="random"> <random:sessionUsedTime formatted="true" /> <random:sessionInactiveTime formatted="true" />
That's it. Hit refresh, and watch the "time created" and "last visit" equivalent counts go up. Very easy and useful.
Advantages:
- Native JAVA session integration
- Less code - Just a couple lines
- Support for multiple windows in the browser (which other code solutions have a hard time with)
Enjoy!


Jul 7, 2008 at 3:55 PM Actually should be able to get most of this without the need for the jar/tld. Do a cfdump of the following and check out the methods contained:
#getPageContext().getSession()#
Some of the methods are:
getCreationTime()
getLastAccessedTime()
getMaxInactiveInterval()
isNew()
getId()
Jul 7, 2008 at 3:58 PM I believe there is an issue with using these. If you reference them, it actually changes their values. I'll try and look up what I found while working on this a few years back.
Jul 7, 2008 at 4:06 PM See: http://jehiah.cz/archive/extended-operations-on-coldfusion-sessions (and related links)
Jul 7, 2008 at 10:20 PM Just checked the java files from servletsuite jar referenced above. They are in fact using getPageContext().getSession(), so we should be okay using it as well.
From their SessionTTLTAG...
HttpSession httpsession = pageContext.getSession();
long l = 0L;
if(null != httpsession)
l = (long)(1000 * httpsession.getMaxInactiveInterval()) - (System.currentTimeMillis() - httpsession.getLastAccessedTime());
Jul 8, 2008 at 12:15 PM @Robert,
That's really interesting. I'll have to go back and compare and see if it makes a difference. This should be a good test with CF8.
Aug 19, 2009 at 2:42 PM Are there any follow ups to this post?
The 4th comment would seem to invalidate this approach - it would suffer the same results as accessing it directly, which of course resets the values.
Any thoughts on how it works, if it does?
Guess I'll have to give it a shot anyway.
Nov 1, 2009 at 10:01 PM You seem to have got the niche from the root, Awesome work