Solved

ColdFusion, detecting session timeout

Posted on 2009-04-08
10
1,925 Views
Last Modified: 2013-12-24
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.

0
Comment
Question by:PhotoMan2000
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 19

Expert Comment

by:erikTsomik
Comment Utility
0
 

Author Comment

by:PhotoMan2000
Comment Utility
Thanks.. regarding this link: http://coldfusion.sys-con.com/node/41925

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.

</cfif>

Open in new window

0
 
LVL 19

Accepted Solution

by:
erikTsomik earned 125 total points
Comment Utility
Or try this
<cfif StructKeyExists(session,nameofthesession>
go
</cfif>
0
 
LVL 1

Expert Comment

by:vonRogue
Comment Utility
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.
0
 

Author Comment

by:PhotoMan2000
Comment Utility
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.)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
> 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.
0
 

Author Comment

by:PhotoMan2000
Comment Utility
Basically none of the above worked.. I had to resort to testing for defined session variable.

Thanks,

<cfif structKeyExists(session, 'membertype')>

do this..

<cfelse>

do soemthine else

</cfif>

Open in new window

0
 

Author Comment

by:PhotoMan2000
Comment Utility
Actually erikTsomik's worked...
0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
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">
    ...


0
 

Author Comment

by:PhotoMan2000
Comment Utility
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</>

<cfelse>

 <cflocaion url="abc.cfm?timeout">

</cfif>

Open in new window

0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now