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.
- 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)