...

View Full Version : Session timer & idle timer



Clawed
12-03-2012, 03:21 PM
Hi,

Like i said in this thread: http://www.codingforums.com/showthread.php?t=283412

I'm building a CMS with session timer and idle timer and i was wondering if it's anything to do with jQuery or JS?!?!?!?

Much help would be appreciated.
Thanks.

Philip M
12-03-2012, 04:31 PM
This script will redirect if no mouse movement has been detected after x seconds, but bear in mind it only works if Javascript is enabled in the browser.


<html>
<head>

<script type = "text/javascript">

var timeInSecs;
var ticker;
var tim;

function check() {
clearInterval(ticker);
clearInterval(tim);
startTimer(6); // start or re-start the timer - 6 seconds - change to 60 for one minute, 3600 for 60 minutes
}

function startTimer(secs){
document.getElementById("message").innerHTML="";
timeInSecs = parseInt(secs);
ticker = setInterval("tick()",1000);
}

function tick() {
var secs = timeInSecs;
document.getElementById("countdown").innerHTML = secs; // REMOVE AFTER TESTING
if (secs>0) {
timeInSecs--;
}
else {
clearInterval(ticker); // stop counting at zero
document.getElementById("message").innerHTML="Unless you move your mouse within 60 seconds you will be disconnected";
tim = window.setTimeout("disconnect()", 6000); // 6 seconds - change to 60000 for 60 seconds
}
}

function disconnect() {
window.location = "http://www.google.com";
}


</script>
</head>

<body onmousemove = "check()">

<div id = "countdown"></div><br>
<!--
Remove countdown div after testing unless you wish to show this.
-->
<div id = "message" style = "font-size:18pt;font-weight:bold;text-align:center;color:red;";></div>


</body>
</html>


"If you think education is expensive, try ignorance." - Derek Bok (1930-), Harvard University President



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum