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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session timeout

Status
Not open for further replies.

timmoser

Programmer
Aug 31, 2002
41
US
My session vars are not timming out when I set them to. In my Application.cfm page I have...


<CFAPPLICATION NAME=&quot;itsite&quot;
SESSIONMANAGEMENT=&quot;Yes&quot;
SETCLIENTCOOKIES=&quot;Yes&quot;
SESSIONTIMEOUT=&quot;#CreateTimeSpan(0,9,30,0)#&quot;>


Because this is driving me nuts I set the timeout in the CF admin to 9hours 30mins too.

When a user logs in I set a session var like so...


<cfif isdefined('FORM.smtLogin')>
<cfquery datasource=&quot;gvdb&quot; name=&quot;validateUser&quot;>
{call s_it_validateuser '#FORM.txtId#', '#FORM.txtPwd#'}
</cfquery>
<CFIF validateUser.recordcount GT 0>
<CFLOCK TIMEOUT=&quot;10&quot; THROWONTIMEOUT=&quot;No&quot; TYPE=&quot;EXCLUSIVE&quot; SCOPE=&quot;SESSION&quot;>
<cfset session.groupList = #valuelist(validateUser.group_name)#>
<cfset session.fullname = #validateUser.fullname#>
<cfset session.uid = #validateUser.uid#>
</CFLOCK>
</CFIF>
</CFIF>


On each page I check for the session var like so...

<CFLOCK TIMEOUT=&quot;10&quot; THROWONTIMEOUT=&quot;No&quot; TYPE=&quot;READONLY&quot; SCOPE=&quot;SESSION&quot;>
<cfif isdefined('session.fullname')>
<cfif #listfind(session.groupList, &quot;Admin&quot;)# GT 0 OR #listfind(session.groupList, &quot;User&quot;)#>
<!--- you are in a group that can access this page --->
<cfset locFullName = #session.fullname#>
<cfset locUid = #session.uid#>
<cfelse>
<!--- You are not good enough to be here --->
You must be a member of the &quot;Admin&quot; or &quot;User&quot; group. Please contact the site admin to gain access to this site.
</cfif>
<cfelse>
<!--- need to login! --->
<cflocation url=&quot;#BaseHREF#/index.cfm?loginfirst=true&quot;>
</cfif>
</CFLOCK>


I also use a JS function to warn them 5 mins before logout. Then I notify them if it does timeout.

All of this worked when I had the timeout max set to 1 hour. I extended the timeout to 9.5 hours (all work day) and the JS seems to work but the session vars timout pre maturely.

So why is the new timeout setting not working?

Thanks in advance for any suggestions.


 
if you specify a timeout in your cfapplication that exceeds the maximum timeout specified in the cf administrator, the value you set in your cfapplication is ignored and the max value from the cf admin is used in its place.

I think that the default for session variables is something like 1 hour, so when you set you session variables to timeout after 9 hours, cf is ignoring that and using the setting in the cf admin.

change the session variable setting in cf admin to something like a day, and the use your cfapplication to do the timeout after 9 hours. that should sort it

Hope this helps!

Tony
 
Thanks arperry, but I set my timeout in cfadmin to:


Application Max Timeout: 2 - 9 - 32 - 0
Application Default Timeout : 2 - 0 - 0 - 0
Session Max Timeout: 1 - 9 - 31 - 0
Session Default Timeout: 1 - 0 - 0 - 0


My Application.cfm has...

<CFAPPLICATION NAME=&quot;itsite&quot; applicationtimeout=&quot;#CreateTimeSpan(1,9,30,0)#&quot;
SESSIONMANAGEMENT=&quot;Yes&quot;
SETCLIENTCOOKIES=&quot;Yes&quot;
SESSIONTIMEOUT=&quot;#CreateTimeSpan(1,9,29,0)#&quot;>


Is there something wrong with my logic in the code in my previous post? The session times out
within an hour on both production and development.

Thanks in advance for you help!

 
Any chance this is releated to the session timeout in IIS? IIS is set to 20 mins, I did change it (to 600 mins) but will have to wait a while before I know anything.
 
Ok so I changed the IIS session timeout to 601 mins and that didn't work. Anyone have any ideas?
 
Hi Tim,

I'm no expert and am actually dealing with a very similar problem - I can't get my host to increast their max timeout beyond 20 mins!

Looking at your settings though, it seems a bit different to what I would have attempted:

Application Max Timeout: 2 - 0 - 0 - 0
Application Default Timeout : 2 - 0 - 0 - 0
Session Max Timeout: 1 - 0 - 0 - 0
Session Default Timeout: 1 - 0 - 0 - 0


Application.cfm

<CFAPPLICATION NAME=&quot;itsite&quot; applicationtimeout=&quot;#CreateTimeSpan(1,0,00,0)#&quot;
SESSIONMANAGEMENT=&quot;Yes&quot;
SETCLIENTCOOKIES=&quot;Yes&quot;
SESSIONTIMEOUT=&quot;#CreateTimeSpan(1,0,0,0)#&quot;>


My understanding is that Application timeout should match the session timeout setttings (why?, I'm not quite sure - just read it somewhere :)). In your admin settings I wouldn't think you would need to set the minutes, as setting a day should be more than enough - perhaps the minutes setting that you have added is overriding the day settings. I am no experienced coder, but that is what I would attempt anyway :)

p.s. I would love a copy of that JS code you are using to notify you users - I need something similar as long as I'm with this host!

 
The problem was fixed when I changed the IIS settings for timeout.

This is the code you are looking for...


(Some of this I got from someone else on this site,
*I think* sorry I can't give them credit)


Each user can set a timeout from 6-570 mins. So first I get the value they set from the db...


<!--- These are the user options --->
<cfquery datasource=&quot;gvdb&quot; name=&quot;getUserOptions&quot;>
{call s_it_tt_getuseroptions '#variables.locUid#' }
</cfquery>
<!--- Header of document --->
<cfoutput QUERY=&quot;getUserOptions&quot; maxrows=&quot;1&quot;>
<cf_header uto=&quot;#getUserOptions.timeoutvalue#&quot; loc=&quot;#appname#&quot; title=&quot;Time Management&quot; msg=&quot;<strong>Welcome #variables.locFullName#</strong>&quot;>
<CFSET templateShowHours=#getUserOptions.usetemplateshowhours#>
</cfoutput>


This is the tag in my header that starts the timmer ...

<CF_TIMEOUTWARNING WarningThreshold=&quot;5&quot; TimeOutMinutes=&quot;#attributes.uto#&quot;>


This is the tags code....

<CFOUTPUT>
<CFPARAM Name=&quot;Attributes.TimeOutMinutes&quot; Default=&quot;20&quot;>
<CFPARAM Name=&quot;Attributes.WarningThreshold&quot; Default=&quot;2&quot;>
<CFPARAM Name=&quot;Attributes.URL&quot; Default=&quot;timeoutwarn.cfm?threshold=#Attributes.WarningThreshold#&timeoutminutes=#Attributes.TimeOutMinutes#&quot;>
<SCRIPT Language=&quot;Javascript&quot;>
// Global variables
var StartTime = new Date();
var StartMils = Date.parse(StartTime.toLocaleString());
var firstpass = true;
var TimeOutMils = StartMils + (60000 * #Attributes.TimeOutMinutes#);
var ThresholdMils = (60000 * #Attributes.WarningThreshold#);
var openurl = &quot;#Attributes.URL#&quot;;

function clientsClock(){
// Create a varible with the current data info
var right_now=new Date();
var the_time=&quot;&quot;;
// Hours come in military time
// To put in civilian time you must check the hours
// To see if they're greater than 12
var right_hours=right_now.getHours()
if (right_hours > 12)
right_hours = right_hours - 12;
the_time+=right_hours;
the_time+=&quot;:&quot;;

// To display leading zeros before the minutes
// Check for minutes less then 10
var right_min=right_now.getMinutes();
if (right_min < 10)
the_time+=&quot;0&quot;;
the_time+=right_min;
the_time+=&quot;:&quot;;

// To display leading zeros before the seconds
// Check for minutes less then 10
var right_sec=right_now.getSeconds();
if (right_sec < 10)
the_time+=&quot;0&quot;;
the_time+=right_sec;

// To display AM or PM assign a varible to A.M. Value
// If the the hours are greater than 12 then switch
// the value to P.M.
var ampm=&quot; A.M.&quot;;
if (right_now.getHours() > 12)
ampm=&quot; P.M.&quot;;
the_time+=ampm;

return the_time;
}

function CountDown(){
clearTimeout('timerLoop');
var CurrentTime = new Date();
var CurrentMils = Date.parse(CurrentTime.toLocaleString());
var RemainingMils = TimeOutMils - CurrentMils;

if(RemainingMils < ThresholdMils && firstpass==true){
var winwarn=window.open(openurl, &quot;warning&quot;,&quot;toolbar=no,status=no,menubar=no,scrollbars=no,resize=no,width=350,height=300&quot;);
firstpass=false;
}else{
if(RemainingMils<=0 && firstpass==false){
//winwarn.close();
window.alert('Your login has expired!');
document.location.href=&quot;/it/index.cfm?logout=true&quot;;
}
}
var timerLoop = setTimeout('CountDown()', 10000);
}
// run CountDown for the first time
CountDown();
</SCRIPT>
</CFOUTPUT>


This is the warning page ...

<!--- timeoutwarn.cfm --->
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Timeout Warning</title>
<SCRIPT language=&quot;JavaScript&quot;>
focusit()
function focusit(){
window.focus()
ttimeout=setTimeout(&quot;focusit()&quot;,100)
}
</SCRIPT>
</head>

<body bgcolor=&quot;#808080&quot;>
<cfoutput>
#timeformat(now())#, #dateformat(now())#   Time Management
<hr color=&quot;##800000&quot;>
<CFSET duration=#URL.timeoutminutes#-#URL.threshold#>
Your login will expire in #URL.threshold# minutes because you have been logged in with no activity for the last #duration# minutes.
Submit any changes to the data (if applicible) now to avoid losing any unsaved information.
<br><br>
Currently your personal options are setup to timeout after being logged in for #URL.timeoutminutes# minutes.
You can change this setting by clicking on the &quot;Options&quot; link located on upper left side of the time sheet.
<br>
</cfoutput>
<hr color=&quot;#800000&quot;>
<div align=&quot;center&quot;><form><input value=&quot;Close&quot; type=&quot;Button&quot; name=&quot;btnClose&quot; onclick=&quot;window.close()&quot;></form></div>
</body>
</html>

Hope this helps








 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top