Solved

ColdFusion, detecting session timeout

Posted on 2009-04-08
10
1,934 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24097505
0
 

Author Comment

by:PhotoMan2000
ID: 24098661
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
ID: 24098809
Or try this
<cfif StructKeyExists(session,nameofthesession>
go
</cfif>
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 1

Expert Comment

by:vonRogue
ID: 24099812
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
ID: 24100074
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
 
LVL 39

Expert Comment

by:gdemaria
ID: 24100222
> 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
ID: 24193995
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
ID: 24194005
Actually erikTsomik's worked...
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 24194333
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
ID: 24194486
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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