Coldfusion graceful timeout

After a user logs in, he is directied to to page1.cfm.
From page 1.cfm user can go to page2.cfm and session.page2 is created. From page2.cfm use can go to page3.cfm and session.page3 is created.

Now, if a user times out, let's say in page3.cfm, Coldfusion leave the URL on page3.cfm

After user logins again, user is directed to page3.cfm but gets an error because session.page3 does not exist.

How can I solve this problem ? I would like user to get the URL of page1.cfm after a time out.

Below please find  my application.cfc

<cfcomponent>

      <cfscript>
           this.name = "Adminpanel";
           this.applicationTimeout = createTimeSpan(0,0,15,0);
           this.clientmanagement= "yes";
           this.loginstorage = "session";
           this.sessionmanagement = "yes";
           this.sessiontimeout = createTimeSpan(0,0,15,0);
           this.setClientCookies = "yes";
           this.scriptProtect = "all";
           this.datasource = "cdmdata";
       </cfscript>



</cfcomponent>
Errol FarroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gdemariaCommented:
At the top of  page3.cfm, just test for the existence of session.page3

<cfif NOT isDefined("session.page3")>
     go to login
</cfif>
0
Errol FarroAuthor Commented:
Thanks for your response. In this example I put one session variable for clarity, but page3.cfm may have multiple session variables. Your suggestion to try out <cfif NOT isDefined("session.page3")> is a good approach. However, is there like a global catch for all the defined session variables ? Or as soon as the time out activates, can one redirect the to page1.cfm from application ?
0
gdemariaCommented:
IMHO, best practice is to define all your session variables in the onSessionStart function in application.cfc so you know they exist everywhere.     Some people over use session variables, if you have a ton of them, there may be a better way of doing this.

If you do this, then the session variables will always exist and you just have to test for their value.   If you need one session variable to always test then why not use the login variable?   That is the one to test if the person's login has expired.

<cfif NOT val(session.user_id)>    ----- when session.user_id no longer has a number, then the user has been timed out
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.