Skip to main content
Participating Frequently
August 4, 2006
Answered

Session End

  • August 4, 2006
  • 3 replies
  • 425 views
How do I code my Application.cfm file to display a message when a user is automatically logged out due to inactivity? In my app, when a user logs out by clicking the Logout link, I have a message the says come back soon or something like that. Anyway, I cannot figure out how to display a message for an inactivity logout. I don't know what the deal is, I must be losing it, this is the 2nd question I've posted today.

I've attached the code below.




    This topic has been closed for replies.
    Correct answer Wilgeno_wnt
    It should be possible to set a meta refresh that is just a little longer than the session timeout. Then have code in place that will notice the session is timedout and display your message. Or just refresh their session depending on the nature of your application.

    3 replies

    doug123Author
    Participating Frequently
    August 15, 2006
    Wilgeno:

    I think I got it.

    Thanks.
    Wilgeno_wntCorrect answer
    Inspiring
    August 7, 2006
    It should be possible to set a meta refresh that is just a little longer than the session timeout. Then have code in place that will notice the session is timedout and display your message. Or just refresh their session depending on the nature of your application.
    Inspiring
    August 4, 2006
    This is not so easy to do. Since HTTP is a stateless technology, the
    client has no idea that the server has timed out until a new request is
    made. If a user is not interacting with the application no requests are
    being made.

    The old way to do this would be use a local javascript function set to
    timeout about the same time that the session is scheduled to timeout.
    Then one use javascript to display a message at this event.

    Now adays you could use Ajax, Flex or some similar technology that keeps
    a connection between the client and the server to push the message when
    the session times out.

    Using the new Application.CFC in place of Application.cfm would make
    this a breeze. Applicaiton.CFC has an onSessionEnd function that is
    called when the server times out the session.

    doug123 wrote:
    > How do I code my Application.cfm file to display a message when a user is
    > automatically logged out due to inactivity? In my app, when a user logs out by
    > clicking the Logout link, I have a message the says come back soon or something
    > like that. Anyway, I cannot figure out how to display a message for an
    > inactivity logout. I don't know what the deal is, I must be losing it, this is
    > the 2nd question I've posted today.
    >
    > I've attached the code below.
    >
    >
    >
    >
    >
    >
    > Using CFMX7 and MySQL v5.0.19
    > =============================
    >
    > ---------------
    > Application.cfm
    > ---------------
    >
    > <cfsilent>
    > <!--- Set the app name, turn on session management, enable cookies,
    > and set application and session variable timeouts of 30 minutes each. --->
    > <cfapplication
    > name="MyApp"
    > clientmanagement="Yes"
    > sessionmanagement="Yes"
    > setclientcookies="Yes"
    > sessiontimeout="#CreateTimeSpan(0, 0, 30, 0)#"
    > setdomaincookies="Yes"
    > applicationtimeout="#CreateTimeSpan(0, 0, 30, 0)#"
    > clientstorage="Cookie"
    > scriptprotect="all">
    >
    >
    > <!--- Set the default session state to false, meaning that
    > by default, users are not logged into the application. --->
    > <cflock name="sLogin_Lock" type="Exclusive" timeout="10">
    > <cfparam name="session.LoggedIn" default="false">
    > </cflock>
    >
    > <!--- If the user isn't logged in or they aren't currently on the
    > login page or registration page, send them to the login page. --->
    > <cflock name="sLogin_Lock" type="ReadOnly" timeout="10">
    > <cfif (NOT session.LoggedIn) AND (CGI.SCRIPT_NAME IS NOT
    > "/myapp/webroot/login.cfm") AND (CGI.SCRIPT_NAME IS NOT
    > "/myapp/webroot/registration.cfm")>
    > <cflocation url="/myapp/webroot/login.cfm" addtoken="No">
    > </cfif>
    > </cflock>
    >
    > <cfif IsDefined('URL.Logout') AND URL.Logout>
    > <!--- Terminate the user's session by deleting all session variables. --->
    > <cflock scope="session" type="Exclusive" timeout="10">
    > <cfset StructClear(session)>
    > </cflock>
    > <cflocation url="/myapp/webroot/login.cfm?Message=#URLEncodedFormat("You
    > have been logged out of your account. Please visit again soon!")#"
    > addtoken="No">
    > </cfif>
    >
    > <!--- Reset the CFID and CFToken cookies to expire session and client
    > variables after the
    > user's browser closes. This isn't necessary if you are using J2EE Session
    > Management. --->
    > <cfif IsDefined("cookie.CFID") AND IsDefined("cookie.CFToken")>
    > <cfcookie name="CFID" value="#cookie.CFID#">
    > <cfcookie name="CFToken" value="#cookie.CFToken#">
    > </cfif>
    >
    > <!--- Check to see if the application has been initialized. If not,
    > set the necessary application variables and initialize the app. --->
    > <cflock timeout="30" throwontimeout="No" type="ReadOnly" scope="Application">
    > <cfset IsInitialized = IsDefined('application.Initialized')>
    > </cflock>
    > <cfif NOT IsInitialized>
    > <cflock type="Exclusive" scope="Application" timeout="10">
    > <cfif NOT IsDefined('application.Initialized')>
    > <cfset application.AdminEmail = "jdoe@example.com">
    > <!--- Set the application.initialized variable to true so that this block
    > of code does not execute every time the Application.cfm file is called. --->
    > <cfset application.Initialized = true>
    > </cfif>
    > </cflock>
    > </cfif>
    > </cfsilent>
    >
    > <!--- Set global values --->
    > I have set up my datasources here using request.dsn, but didn't include them
    > since they are not relevant to my question.
    >