Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default Page for Session Timeout

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
0
0
US
Hi,

Here's a question hopefully some of you will love.

I have an application that's currently being tested.

Well, my lovable users are purposely letting the browser session sit until the session vars timeout. Then, when they try to click on something, if I am using a session var at the beginning of a page, then of course they get the adorable "Session var X doesn't exist."

I know there's some Exception Handling that I can use that will stop this. I'm not an expert at utilizing, but I think it is the <cftry>/<cfcatch>. I know I have to enclose my code within these tags, but do I do that for every page?

Could someone elaborate more about what I'd need to do? Also, if there's any settings in the CF Admin that I could set, I'd really appreciate someone telling me. Also, how do I redirect users to a default page telling them their session has timed out? Is that also set in CF Admin.

I appreciate any assistance you can give.

Thanks,
scripter73


Change Your Thinking, Change Your Life.
 
You can create a file that you include in every page (by using Application.cfm) to check for a live session. If the session var is timed out, redirect to a page to tell the user this.
You can also redirect the user to a warning page after the time has expired by using the redirect in the header.
Here is some code to test a variable, the time out is set to 2 hours.
<code>
<CFAPPLICATION NAME = &quot;name&quot; SESSIONMANAGEMENT=&quot;Yes&quot; SESSIONTIMEOUT=&quot;#CreateTimeSpan(0,2,0,0)#&quot;>
<cflock timeout=&quot;30&quot; throwontimeout=&quot;Yes&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
<cfif Not IsDefined(&quot;session.var_name&quot;)>
<cflocation url=&quot; >
</cfif>
</cflock>
</code>

Erwin Oosterhoorn
Analyst Programmer,
ice hockey player/fan.
 
To expand on erwino's suggestion, I use a custom tag called &quot;cf_timeout&quot; (it can be downloaded at the Macromedia Exchange) which sends the user a popup to notify them their session is about to expire in &quot;x&quot; minutes. Then, if the user does nothing, when the session expires it automatically redirects them to whatever page you specify.

Hope This Helps!

Ecobb
- I hate computers!
 
Hi erwino/ecobb,

Thanks so much for responding to quickly! Those are great suggestions.

Ecobb, I'll go out to Macromedia's site and lookup that function.

Erwino,

If I update my application.cfm file with the information you set for me and include a redirect to a page, then what do I have to include on every page of my application? You had mentioned I had to do some sort of include on the other pages.

Also, I have several session vars, so is there a way to say:

<cfapplication...>

<cfif Not IsDefined(&quot;session.sessionid&quot;)>
....redirect here ....
</cfif>

Isn't session.sessionid indicative of any session vars?

Thanks for all of your help. I really appreciate it.

scripter73


Change Your Thinking, Change Your Life.
 
the Application.cfm file (remember the capitalisation) includes on all files you create under that site. So if you have a check in that page all pages will include the check.
If you create a session variable that each user has at the start of the session, you only have to check for that variable to see if the session is still 'live'.
I am not aware of a generic name that test any kind of session vars, but you can get all variables set as a struct.
<code>
<cflock timeout=&quot;10&quot; throwontimeout=&quot;Yes&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
<CFSET keysToStruct = StructKeyArray(session)>
<CFLOOP index=&quot;i&quot; from=&quot;1&quot; to=&quot;#ArrayLen(keysToStruct)#&quot;>
<P><CFOUTPUT>Key#i# is #keysToStruct# Value#i# is #session[keysToStruct]#</CFOUTPUT></P>
</CFLOOP></cflock>
</code>
This will show all session variables set at that time.


Erwin Oosterhoorn
Analyst Programmer,
ice hockey player/fan.
 
Hi erwino,

I tried what you recommended and here's what I have.

In my application.cfm file:

<CFAPPLICATION NAME = &quot;ACCTINQUIRY&quot; SESSIONMANAGEMENT=&quot;Yes&quot; SESSIONTIMEOUT=&quot;#CreateTimeSpan(0,0,3,0)#&quot;>
<cflock timeout=&quot;30&quot; throwontimeout=&quot;Yes&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
<cfif Not IsDefined(&quot;session.sysdate&quot;)>
<cflocation url=&quot;timeout.cfm&quot;>
</cfif>
</cflock>



But what happens is that when I go to the homepage of my application, it gets stuck in an endless loop where it continually tries to load timeout.cfm.

Let me tell you what's happening. The homepage of my application creates/initializes a var called session.sysdate. Then I go through the various pages of my application. What I'm trying to avoid is someone trying to access these pages when the homemade session vars I created aren't there.

I think the reason I'm getting stuck in this loop is because the application.cfm is invoked first, and I can't get to the point where I init the session.sysdate.

Hope that makes sense. Also, I changed the timeout to 3 minutes just because I want to time them session vars out sooner.

Any advice is greatly appreciated.

Thanks,
scripter73


Change Your Thinking, Change Your Life.
 
All you need to do is add another IF statement, like this:

<cfif #cgi.script_name# NEQ &quot;HomepageName.cfm&quot;>

<cflock timeout=&quot;30&quot; throwontimeout=&quot;Yes&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
<cfif Not IsDefined(&quot;session.sysdate&quot;)>
<cflocation url=&quot;timeout.cfm&quot;>
</cfif>
</cflock>

</cfif>

This will allow the code to execute on every page EXCEPT your homepage.

Hope This Helps!

Ecobb
- I hate computers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top