I nice piece of javascript to alert the user X minutes before their session will timeout. Then again when their session actually times out. After they click OK on the last message, it redirects back to the login page (or wherever you want). The only variables you need to edit are warn_sec, timeout_sec, and window.location.href.
// ***** Session Timeout Warning and Redirect mReschke 2010-09-29 ***** //
function InitSessionTimer() {
/* mReschke 2010-09-29 */
warn_sec = 59 * 60 * 1000; //Warning time in milliseconds
timeout_sec = 60 * 60 * 1000; //Actual timeout in milliseconds
show_warning = true;
epoch = new Date().getTime();
CheckSessionStatus();
}
InitSessionTimer();
function CheckSessionStatus() {
/* mReschke 2010-09-29 */
//Check for session warning
epoch2 = new Date().getTime();
if (epoch2 > epoch + warn_sec && epoch2 < epoch + timeout_sec && show_warning) {
show_warning = false; //Don't show again
alert_shown = true;
alert("Your session will timeout in " + Math.round((timeout_sec - warn_sec) / 60000) + " minute, please click a button or navigate to another page to refresh your session before it expires.");
down = setTimeout("CheckSessionStatus();", 1000);
} else if (epoch2 > epoch + timeout_sec) {
alert("Your session has timed out.");
window.location.href = 'http://yoursite.com/some/page/to/redirect/to';
} else {
down = setTimeout("CheckSessionStatus();", 1000);
}
}
// ******************************************************************** //