1

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

user1394925
  • 754
  • 9
  • 28
  • 51
  • with php session, javascript handle event from document (mousemove, click, keypress) you can do that – James Jun 01 '12 at 07:40

2 Answers2

1

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.

Cache-Control HTTP Headers

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

Community
  • 1
  • 1
mprabhat
  • 20,107
  • 7
  • 46
  • 63
0

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;
    }
} 
jbrtrnd
  • 3,815
  • 5
  • 23
  • 41