Solved

ColdFusion, detecting session timeout

Posted on 2009-04-08
10
1,927 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
 
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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
X-Frame-Options - click-jacking 7 56
how to configure and install nginx ? 1 429
Has my website been infiltrated? 21 63
WEB Farm 6 60
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

13 Experts available now in Live!

Get 1:1 Help Now