Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

Notifying the user that a session has expired

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
g8torjoe
Asked:
g8torjoe
  • 2
  • 2
1 Solution
 
mkishlineCommented:
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
 
gdemariaCommented:

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

0
 
OneiroidCommented:
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
 
gdemariaCommented:

 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
 
OneiroidCommented:
> 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now