Important alert: (current site time 7/15/2013 1:23:52 PM EDT)
 

VB icon

Auto Expire

Email
Submitted on: 9/10/2002 6:45:02 PM
By: MarkParter 
Level: Intermediate
User Rating: Unrated
Compatibility: JavaScript
Views: 13564
(About the author)
 
     This code is to be used in conjuction with an ASP based website that has a Session timeout. Once the session has expired it will warn the user and then redirect them to a predefined page.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :Auto Expire
'**************************************
The following form and body tag needs to be in every page using the Auto Expire function.
<body onload="timeIt()">
<form name="timerform" method="post" action="">
<input type="hidden" name="clock" value="20" />
</form>
Set the value of the hidden field to how long the session lasts.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Auto Expire
' Description:This code is to be used in conjuction with an ASP based website that has a Session timeout. Once the session has expired it will warn the user and then redirect them to a predefined page.
' By: MarkParter
'
' Inputs:Page to redirect to and how long the session lasts for.
'
' Side Effects:This is basically a glorified timer function so 20 minutes to the script might be different to the server!
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=3156&lngWId=14'for details.'**************************************

You can either place the following in the <HEAD> section of each page like so:
<script type="text/javascript">
expiredURL = "http://www.yoursite.co.uk/login.asp?action=logout";
function Minutes(data) {
	for (var i = 0; i < data.length; i++)
	if (data.substring(i, i + 1) == ":")
	break;
	return (data.substring(0, i));
}
function Seconds(data) {
	for (var i = 0; i < data.length; i++)
	if (data.substring(i, i + 1) == ":")
	break;
	return (data.substring(i + 1, data.length));
}
function Display(min, sec) {
	var disp;
	if (min <= 9) disp = " 0";
	else disp = " ";
	disp += min + ":";
	if (sec <= 9) disp += "0" + sec;
	else disp += sec; 
	return (disp);
}
function Down() { 
	sec--; "& vbCrLf
	if (sec == -1) { sec = 59; min--; }
	document.timerform.clock.value = Display(min, sec);
	if (min == 0 && sec == 0) {
	msg = "Session Expired\r\rBecause no requests have been made in the last 20 minutes, your session has been terminated. Please login again.";
	alert(msg);
	window.location.href = expiredURL;
	}
	else down = setTimeout("Down()", 1000);
	}
	function timeIt() {
	min = 1 * Minutes(document.getElementById('timerform').clock.value);
	sec = 0 + Seconds(document.getElementById('timerform').clock.value);
	Down();
	}
</script>
or you can put it in a .js file and use an include:
<!-- #INCLUDE file="expire.js" -->


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
3/22/2003 4:00:48 AM

The script is good, but what happens if you open other pages in new windows. After 20 minutes your main pages goes away and left child windows alone? Try to fix it :)
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.