It is very common to store session cookies from php to the browser to set session ending information. on the server side the expire information is stored into a db. On every user request server updates cookie and database. With jquery cookie plugin you can check when the session expires. You can do it with polling(not pooling) like the others suggest on set a timer event to the time the session expires.
EDIT
I have a similar application that I'm working on. Here is what I did:
in php on every ajax request i set the cookie
$exp_gmt = gmdate("D, d M Y H:i:s", time() + $this->allowcache_expire * 60)." GMT";
header("Expires: ".$exp_gmt);
header("Cache-Control: max-age=".$this->allowcache_expire * 60, false);
then I use in client side this jquery plugin (sorry I can't remember where I found it)
jQuery.cookie = function(d, e, b) {
if(arguments.length > 1 && String(e) !== "[object Object]") {
b = jQuery.extend({}, b);
if(e === null || e === undefined) {
b.expires = -1
}
if( typeof b.expires === "number") {
var g = b.expires, c = b.expires = new Date();
c.setSeconds(c.getSeconds() + g)
}
e = String(e);
return (document.cookie = [encodeURIComponent(d), "=", b.raw ? e : encodeURIComponent(e), b.expires ? "; expires=" + b.expires.toUTCString() : "", b.path ? "; path=" + b.path : "", b.domain ? "; domain=" + b.domain : "", b.secure ? "; secure" : ""].join(""))
}
b = e || {};
var a, f = b.raw ? function(h) {
return h
} : decodeURIComponent;
return ( a = new RegExp("(?:^|; )" + encodeURIComponent(d) + "=([^;]*)").exec(document.cookie)) ? f(a[1]) : null
};
Also I have a clock on the page:
showTime : function() {
var today = new Date();
var curr_date = today.getDate();
var curr_month = today.getMonth() + 1;
var curr_year = today.getFullYear();
var curr_hour = today.getHours();
var curr_min = today.getMinutes();
var curr_sec = today.getSeconds();
if(curr_date < 10)
curr_date = '0' + curr_date;
if(curr_month < 10)
curr_month = '0' + curr_month;
if(curr_hour < 10)
curr_hour = '0' + curr_hour;
if(curr_min < 10)
curr_min = '0' + curr_min;
if(curr_sec < 10)
curr_sec = '0' + curr_sec;
var curr_full = curr_date + "/" + curr_month + "/" + curr_year + "<br />" + curr_hour + ":" + curr_min + ' <span style="font-size:0.8em">' + curr_sec + '</span>';
$('#clock').html(curr_full);
setTimeout("showTime()", 1000);
}
At the end of the clock function you may read the cookie and compare it with the current time to see if it is expired.