Solved

ColdFusion, detecting session timeout

Posted on 2009-04-08
10
1,930 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
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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Are date-time stamps in Microsoft IIS log files in GMT +0? 3 60
How to switch email hosts (part 2) 11 70
htaccess restrict subdomain 4 131
Moving web servers into a DMZ? 3 67
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

838 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