Welcome to WebmasterWorld Guest from 54.162.105.6
Forum Moderators: open
<script type="text/javascript">
document.location.href = 'login.php';
</script>
<!DOCTYPE html>
<html>
<head>
<title>Session Management Test</title>
</head>
<body>
<script>
var sessionMgr = {
sessionTimeout: -1,
notifyUserTimeout: -1,
notifyTimerId: -1,
sessionTimerId: -1,
remaining: 0,
init: function (debug) {
sessionMgr.sessionTimeout = 2; // 15 minutes
sessionMgr.notifyUserTimeout = sessionMgr.sessionTimeout - 1;
sessionMgr.setNotification.call(sessionMgr);
sessionMgr.setSessionTimeout.call(sessionMgr);
sessionMgr.remaining = sessionMgr.sessionTimeout * 60;
if (debug) {
sessionMgr.showDebug();
}
},
setNotification: function () {
clearTimeout(this.notifyTimerId);
this.notifyTimerId = setTimeout(function () {
// Display message to user that session is about to expire
// Don't use an alert or confirm, though, as they will block
// the processing and screw up the remaining time so create your
// own styled dialog instead.
// The dialog should give the user the option of keeping the
// session alive, which would in turn call this.setNotification
// and this.setSessionTimeout to reset the session.
if (confirm('Session about to expire. Keep alive?')) {
sessionMgr.setNotification.call(sessionMgr);
sessionMgr.setSessionTimeout.call(sessionMgr);
}
}, this.notifyUserTimeout * 1000 * 60);
},
setSessionTimeout: function () {
clearTimeout(this.sessionTimerId);
this.sessionTimerId = setTimeout(function () {
// User's session has expired
// Redirect to login page
window.location = 'login.php';
}, this.sessionTimeout * 1000 * 60);
this.remaining = this.sessionTimeout * 60;
},
showDebug: function () {
var el = document.createElement('div');
el.id = 'sessionMgrDebug';
document.body.appendChild(el);
setInterval(function () {
el.innerHTML = 'Session Timeout in: ' + sessionMgr.remaining--;
}, 1000);
}
};
sessionMgr.init(true);
</script>
</body>
</html>
<!-- REDIRECT -->
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
result = ajaxRequest.responseText;
document.getElementById(div_id).innerHTML = parseScript(result);
}
}
function parseScript(_source) {
var source = _source;
var scripts = new Array();
// Strip out tags
while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
var s = source.indexOf("<script");
var s_e = source.indexOf(">", s);
var e = source.indexOf("</script", s);
var e_e = source.indexOf(">", e);
// Add to scripts array
scripts.push(source.substring(s_e+1, e));
// Strip from source
source = source.substring(0, s) + source.substring(e_e+1);
}
// Loop through every script collected and eval it
for(var i=0; i<scripts.length; i++) {
try {
eval(scripts[i]);
}
catch(ex) {
// do what you want here when a script fails
}
}
// Return the cleaned source
return source;
}