Keeping sessions alive with Ajax

One often needed functionality of a web portal is to check whether a specific user is online. This can be achieved by keeping the session alive via Ajax call. At the site you are currently on (, it is done in the following way:

var interval = 1000 * 60 * 2; // 2 minutes
$(document).ready(function() {
    setInterval(function() {
        $.post('/ajax.php', {keepalive: "hoplaa"}, function(data) {});
    }, interval);

Note that in order this example script to work, you should include jQuery JavaScript library to your page.

The bolt in the photo at the left was on a road in Turku, from someones engine, where it used to serve at the bottom of the oil container. More photos from Turku are available at Flickr.