Solved

Notifying the user that a session has expired

Posted on 2006-10-20
5
419 Views
Last Modified: 2013-12-24
Is there an onSessionEnd event or something similar that fires when a CF session expires where I can notify the user that the session timed out?  Unfortunately my host is only running CF 5 so I need something that will work on that version.

Thank you!
0
Comment
Question by:g8torjoe
[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
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:mkishline
ID: 17774862
I haven't seen anything along those lines, but you can probably rig up a hack pretty easy. In the Application.cfm file just have something like:

<!--- If people are trying to get to the login page, don't show them the message --->
<cfif SCRIPT_NAME NEQ "login.cfm" AND (NOT isDefined('session') OR NOT isDefined('session.loggedin'))>
  <cfset session.msg = "Your session has expired, please login again." />
  <cflocation url="login.cfm" />
</cfif>

<!--- login.cfm --->
<cfif isDefined('session.msg')><cfoutput>#session.msg#</cfoutput><cfset StructDelete(session,'msg') /></cfif>
Login form info
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 17775256

 coldfusion MX has an  end of session event.  You need to use  application.cfc   instead of  application.cfm   to use it though

0
 
LVL 4

Expert Comment

by:Oneiroid
ID: 17785702
What I like to do is just set an additional variable in my Application.cfm:
<cfparam name="application.TimeOut" default="0">

When the user logs in, set application.TimeOut = 1.

If the session expires / doesn't exist, check if TimeOut equals one. If so, launch your notification. If it still equals 0, do not launch your notification because a login never occured.

Additionally, when the user logs out, set application.TimeOut = 0 again so that the user does not get an erroneous time out message later. Also set application.TimeOut = 0 when notification of an exipred session is given so that the user does not keep getting that message.

Example - session expired:

<cfif session.UserID eq "">
      <cfif application.TimeOut is 1>
            <cfset message = "Your session has timed out.">
            <cfset application.TimeOut = 0>
      </cfif>
      <cfinclude template="login.cfm">
</cfif>

Example - logout:

<cfif isdefined("logout")>
      <cfset session.UserID = "">
      <cfset application.TimeOut = 0>
      <cfset message = "You have successfully logged out.">      
      <cfinclude template="login.cfm">
</cfif>
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 17786097

 Oneiroid, application scope variables are shared by all users.

  If you set the value of application.time-out to 1 for user A, then it will be 1 for user B, C, D, etc.    If user B sets it to 0, then it will change for A, C, D, E, etc...   Application scope variables are not a good choice for user specific values.

  Session variables also time-out and are specific to only one user.

  There is no need to set a flag "time-out" you can simply check to see if the session variable is no longer available.

  <cfif NOT structKeyExists(session,"username")>
     <cflocation url="login.cfm">
   </cfif>

 or like mkishline  shows above..

0
 
LVL 4

Accepted Solution

by:
Oneiroid earned 500 total points
ID: 17786369
> application scope variables are shared by all users.
Yes, sorry for that. gdemaria, you are correct.

> Session variables also time-out and are specific to only one user.
I believe this is was the Author is asking about: TimeOut event on a session variable.

I did, however, come across a rather creative approach for this problem here:
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21612933.html?query=coldfusion+session+timeout&clearTAFilter=true

0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

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…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

734 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