0

I am exploring a potential in-house content delivery system where we have to keep track of student time-on-task. As long as the student is interacting with the page, there is no problem. If the student goes out for lunch leaving the page open, the session should time-out and they will not get credit for their on-line time after the timeout.

I already figure I can easily capture events like navigating away from a page and recording that fact with PHP into the student's record in MySQL, but what is the best way to time a student out? JavaScript? I looked around and haven't found a good explanation yet.

Thanks for any help!

---------- EDIT --------------

After Floris' suggestion about looking at a particular post about idleness, most suggested a JQuery solution, but one poster had a simple solution with no JQuery. Does this code seem like it will work? It looks fine to me:

var inactivityTime = function () {
    var t;
    window.onload = resetTimer;
    document.onmousemove = resetTimer;
    document.onkeypress = resetTimer;

    function logout() {
        alert("You are now logged out.")
        //location.href = 'logout.php'
    }

    function resetTimer() {
        clearTimeout(t);
        t = setTimeout(logout, 3000)
        // 1000 milisec = 1 sec
    }
};
Chris Wilson
  • 203
  • 1
  • 6
  • 14
  • use javascript to build a timer that send keepalive like msg every 1m – farmer1992 Jan 26 '13 at 05:10
  • Oh boy, student control. They're not yet forced to wear NFC tags so their activities could be tracked more easily? Joking... anyway, using JavaScript won't do much for the savvy of the bunch, you better take @Arnold's suggestion and do any interaction checks server-side. ;) – TildalWave Jan 26 '13 at 05:31

2 Answers2

0

Use JavaScript to detect when a user becomes idle. When a user become idle fire an AJAX call that blows away any cookies or session data.

mmattax
  • 27,172
  • 41
  • 116
  • 149
0

A student can easily fake it, if you let the browser do the work. Instead I'd turn it around and log whenever a user does an action (like go to a different page). The time spend is the sum of the time between an action and the next (delta time), but exclude if delta time is bigger than 15 minutes.

Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82