ColdFusion, detecting session timeout

Is there a SIMPLE way to detect a session time out in ColdFusion and force a redirect to a specific URL?  Either due to no activity or the sessiontimeout="#CreateTimeSpan(0,1,0,0)#" has expired.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

erikTsomikSystem Architect, CF programmer Commented:
PhotoMan2000Author Commented:
Thanks.. regarding this link:

It's from 2000 - hasn't CF come out with anything less complex? Such as doing something like this:

(Which is what I'm really after)
<cfif session.sessiontimeout LT '00:00:00:20'>
do something - like a cflocation or an alert.

Open in new window

erikTsomikSystem Architect, CF programmer Commented:
Or try this
<cfif StructKeyExists(session,nameofthesession>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

The CFIF code will not work, due to the way sessions are timed. As soon as a user requests a page, their session timeout is reset to it's default (20 minutes for a default CF install). Basically, this means that you can't see how much time is left in that specific session by using server side code. The only way you'll be able to redirect them is by using something like the javascript code erik mentioned above. I hope this clears things up a bit.
PhotoMan2000Author Commented:
Thanks vonRoque..  It's too bad Adobe  hasn't thought of such a simple concept to have native time feature.
(Note.. I'll be out of the office for a week, so pleases don't freak if I don't get back to this quesion.)
> It's too bad Adobe  hasn't thought of such a simple concept to have native time feature.

This is a browser level issue, client-side, coldfusion or any other server-side language cannot have any control over it.   That's why vonRoque suggested javascript because it runs client-side.

When the page loads, set a timer running that is in-line with your session time-out.   Have the javscript redirect you to a login page that drops the session.
PhotoMan2000Author Commented:
Basically none of the above worked.. I had to resort to testing for defined session variable.


<cfif structKeyExists(session, 'membertype')>
do this..
do soemthine else

Open in new window

PhotoMan2000Author Commented:
Actually erikTsomik's worked...
I guess we misinterpreted your question.   We thought you meant that if the page sits idle for 20 minutes, the page would automatically change to a session-timed-out page without user intervention.   Banking sites or credit card sites often do this in case someone walks away from the computer.

The solution with session variable testing will work, of course (that's what they're for) when the user attempts to go to another page.   The new page will catch the fact that the session variable no longer exists and sends you to the login page (or whatever).

We over-thought your question expecting it would be more than just testing for a session variable..
Another approach is...

<cfif NOT isDefined("session.user_id"")
    <cfinclude template="login.cfm">

PhotoMan2000Author Commented:
Yes. that is what my original question was.  But in doing searching and the input fom EE, and without having to figure out a JavaScript that would accomplish the task (noone actually provided me with a script) - i had to resort to testing for the existance of a defined variable name. Which does no exist after the session times out.  

So, iF the user tries to load a page and the value is not there, they are sent back to the login page with an  message being displayed. Not as user friendly as automatically forwarding the user, but it got the job done.

Thanks for the feedback.
<cfif structKeyExists(session, 'membertype')>
 <cfelse if session.membertype EQ XYX>do this</>
 <cflocaion url="abc.cfm?timeout">

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.