Reputation: 752
I want to know if it is possible that when the user has not typed or clicked on the application for a long time that the document becomes expired. also if the user has clicked on the refresh button, then the document becomes expired?
Can somebody show an example of how this can be done? I don't know whether it is php or javascript which does this.
Thanks
Upvotes: 1
Views: 110
Reputation: 20323
I am not an expert in PHP but rules for page expiry remains same, you will have to set appropriate header for it not to be cached by the browser.
So for 2nd question you will do something like this:
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
More info at - Read Example #2 Caching directives.
For 1st you can use a combination of javascript events like mousemove, click e.t.c to check if user is active or not, if not then you can show some confirmation dialog.
A nice jQuery plugin idle monitor
Detecting idle time in JavaScript elegantly
Upvotes: 1
Reputation: 3833
You can use setTimeout javascript function to check every X milliseconds if the user have trigger the event click
or keypress
on the document.
For example :
var expired;
$(document).ready(function(){
$(document).click(function(){
expired = false;
});
$(document).keypress(function(){
expired = false;
});
setTimeout("check_expired",60000); // Every minutes
});
function check_expired() {
if(expired == true) {
//DO SOMETHING
} else {
expired = true;
}
}
Upvotes: 0