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

How to extend a session

Status
Not open for further replies.

bnymk

Programmer
Feb 7, 2003
296
US
Hello all:

In Application.cfm I have implemented a routine that will pop up a window that will alert a user 3 minutes before their session is about to expire (after 17 minutes of their total 20 minutes session). The website has three frames. The top frame has navigation links that upon clicking displays data on both the left-hand and right-hand frames. While users are clikcing away, since the whole window hasn't been refreshed, the pop-up will show up after 17 minutes even though users are interacting with the server while they are clikcing on the links and getting data that is displayed on the left and right hand frames. How can I prevent the pop up from displaying while there is user activity going on inside the frames??? Any ideas would be greatly appreciated on how solve this issue.

Thanks.

"Behind every great fortune there lies a great crime", Honore De Balzac
 
Well the popup is generated by javascript..

I'm aware of the timer functions of javascript, but I'm sure that when you leave or refresh a page, those timers are destroyed and the new page's code is priority..

It seems like you could refresh the frame on some mouse clicks, or make it part of the header... a 17 minute popup... when they leave the page the popup is destroyed and a new one is created.

Your popup window... Is it a .cfm or .html file? If its .cfm.. If its html, you're ok on that.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
By just refreshing the frames doesn't reset the time that is defined in the Application.cfm. I tried that and it didn't work. Anyway, here is what my code looks like in the Application.cfm page.

<cflock scope="APPLICATION" type="EXCLUSIVE" timeout="10"><cfparam name="ATTRIBUTES.Time" default="17"></cflock>
<cflock scope="APPLICATION" type="EXCLUSIVE" timeout="10"><cfparam name="ATTRIBUTES.SessionTime" default="20"></cflock>

<cfoutput>
<!--- The time when the warning will be displayed in miliseconds --->
<cfset thisLaunchTime = (ATTRIBUTES.Time * 60 * 1000)>
<!--- The time how long the session will last in miliseconds --->
<cfset thisSessionTime = (ATTRIBUTES.SessionTime * 60 * 1000)>
<!--- The time remaining before the session expires in miliseconds --->
<cfset thisExpireTimeMils = (thisSessionTime - thisLaunchTime)>
<!--- The time remaining before the session expires in seconds --->
<cfset thisExpireTime = (ATTRIBUTES.SessionTime * 60 - ATTRIBUTES.Time * 60)>
<!--- The time remining before the session expires in minutes --->
<cfset thisExpire = (ATTRIBUTES.SessionTime - ATTRIBUTES.Time)>
</cfoutput>

<script language="Javascript">
<!--
var sessionLength;
<!--- Delay it by one second so the status counter matches with the counter in the pop up window. --->
var counter = <cfoutput>#thisExpireTime#</cfoutput> + 1;
<!--- Maximum allowable idle time in minutes --->
sessionLength = <cfoutput>#ATTRIBUTES.SessionTime#</cfoutput>;
<!--- Minutes when warning will be alerted if idle --->
var warningLength = <cfoutput>#ATTRIBUTES.Time#</cfoutput>;
var logOffTime = sessionLength - warningLength;
var logOffTimeMils = logOffTime * 60000;

<!--- A function that will display the session expired main page that will clear out user's session --->
function LogOut(){
window.location.href = "/SessionLogOut.cfm";
}
<!--- A function that will display the seconds remaining before session expires on the status bar --->
function Update(){
counter--;
window.status = "Time remaining before session expires: " + counter + " seconds.";
ID=window.setTimeout("Update();", 1000);
}
<!--- A function that will display the pop up window that will notify users that their session --->
<!--- is about to expire if there is no activity from them in the next five minutes. It will also display --->
<!--- the remaining time in seconds --->
function warning(warningLength){
var aw = screen.availWidth;
var ah = screen.availHeight;

var winWidth = 590;
var winHeight = 185;

var winLeft = (aw - winWidth) / 2;
var winTop = (ah - winHeight) / 2;

if(timeOutWindow){
timeOutWindow.document.open();
}
else{
var timeOutWindow = window.open("", "timeOutWindow", "width=" + winWidth + ",height=" + winHeight + ",left=" + winLeft + ",top=" + winTop);
timeOutWindow.document.open("text/html", "replace");
}
timeOutWindow.document.writeln("<html><head><title>Session Expiration Warning</title>" +
"<style>" +
"body{font-family:Arial;font-size:14pt;font-Weight:bold;color:Red}" +
"input.readonly {font-family:Arial;background-color:#6a6b95;border:none;border-width:0;color:Red;font-size:11pt;font-Weight:bold;text-align:center;}" +
"td {font-family:Arial;font-size:10pt;color:white}" +
"</style>" +
"<script language=\"JavaScript\">" +
"var counter = <cfoutput>#thisExpireTime#</cfoutput>;" +
//call update function in every second after the first load
"ID=window.setTimeout(\"Update();\",1000);" +
"function Update(){" +
"counter--;" +
"document.form1.input1.value=counter;" +
//set another timeout for the next count
"ID=window.setTimeout(\"Update();\",1000);" +
"}"+
"function extendSession(){" +
"window.opener.location.reload();" +
"self.close();" +
"}" +
"setTimeout(\"self.close();\", " + logOffTimeMils + ");</script>" +
"</head><body bgcolor=\"#6a6b95\" onblur=\"this.focus()\">");
timeOutWindow.document.writeln("<form name=\"form1\"><center>Warning:</center><br><table><tr><td>Your current session has been active for " + warningLength + " minutes. To extend your session, please close this warning pop-up, then press your <b>F5</b> key to refresh the whole window. ");
timeOutWindow.document.writeln("Otherwise your session will expire in <cfoutput>#thisExpire#</cfoutput> minutes or in<input type=\"text\" name=\"input1\" size=\"1\" readonly class=\"readonly\">seconds. The time left before your session expires is also displayed on the status bar of the main window.");
timeOutWindow.document.writeln("</td></tr></table></form>");
timeOutWindow.document.writeln("<p><center><input type=\"Button\" name=\"closeBtn\" value=\"Close Window\" onclick=\"window.close();\"</center></body></html>");
timeOutWindow.document.close();
Update();
setTimeout("LogOut()", logOffTimeMils);
}
<!--- A function that will invoke the two defined functions after a specified period of time. --->
function ExpireSession(sessionLength){
setTimeout("warning(warningLength)", warningLength * 60000);
setTimeout("LogOut()",<cfoutput>#thisSessionTime#</cfoutput>);
}
ExpireSession(sessionLength);
//-->
</script>



"Behind every great fortune there lies a great crime", Honore De Balzac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top