简体   繁体   中英

session timeout on page with ajax auto-refresh

Good day folks - be gentle - I'm a first time poster.

I have a page on a php-based web site that uses an AJAX-based call to update a DIV tag with a table of data every 5 or 10 seconds. The security folks where I work want me to make sure users get logged out after 15 minutes of inactivity. To that end I put in

<script type="text/javascript">
window.setTimeout("location=('/mysite/session_timeout.php');",900000);
</script>

The problem is, of course, that the AJAX refresh of the table is 'resetting' the timeout counter ... So my question is basically "Is there a client-side way to either mitigate the ajax call resetting the clock so to speak, or do I need to address this with php's _SESSION array and hide values in there, or does someone have something better than that?"

Thanks for any help you all can provide.

You can Store the start time of that page and update you table data without reloading the page. and check for the start time and destroy session accordingly.

You can try something like this

$_SESSION['activity'] = time();

    function check_if_logged_in() {
        if(time() - $_SESSION['activity'] > 900) { 
            // Do redirect or take other action here
        }
    }

Or you can use this jQuery plugin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM