Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p><strong>EDIT</strong></p> <p>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</p> <pre><code>$exp_gmt = gmdate("D, d M Y H:i:s", time() + $this-&gt;allowcache_expire * 60)." GMT"; header("Expires: ".$exp_gmt); header("Cache-Control: max-age=".$this-&gt;allowcache_expire * 60, false); </code></pre> <p>then I use in client side this jquery plugin (sorry I can't remember where I found it)</p> <pre><code>jQuery.cookie = function(d, e, b) { if(arguments.length &gt; 1 &amp;&amp; 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 }; </code></pre> <p>Also I have a clock on the page:</p> <pre><code>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 &lt; 10) curr_date = '0' + curr_date; if(curr_month &lt; 10) curr_month = '0' + curr_month; if(curr_hour &lt; 10) curr_hour = '0' + curr_hour; if(curr_min &lt; 10) curr_min = '0' + curr_min; if(curr_sec &lt; 10) curr_sec = '0' + curr_sec; var curr_full = curr_date + "/" + curr_month + "/" + curr_year + "&lt;br /&gt;" + curr_hour + ":" + curr_min + ' &lt;span style="font-size:0.8em"&gt;' + curr_sec + '&lt;/span&gt;'; $('#clock').html(curr_full); setTimeout("showTime()", 1000); } </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload