Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start();
- // http://www.daniweb.com/web-development/php/threads/124500/session-time-out-in-php
- // set timeout period in seconds
- $inactive = 600;
- // check to see if $_SESSION['timeout'] is set
- if(isset($_SESSION['timeout']) ) {
- $session_life = time() - $_SESSION['start'];
- if($session_life > $inactive)
- { session_destroy(); header("Location: logoutpage.php"); }
- }
- $_SESSION['timeout'] = time();
- ?>
- <html>
- <head>
- <script type="text/javascript">
- function start_onload(){
- var expire_time = new Date().getTime() + 1000*<?php echo $inactive; ?>;
- //console.log(expire_time);
- countdown_session_timeout();
- function countdown_session_timeout() {
- var current_time = new Date().getTime();
- var remaining = Math.floor((expire_time - current_time)/1000);
- var timeout_message = document.getElementById('timeout_message');
- if (remaining>0) {
- timeout_message.innerHTML = 'Session will expire in '+ Math.floor(remaining/60) + ' min. ' + (remaining%60) + ' sec.';
- setTimeout(countdown_session_timeout, 1000);
- } else {
- timeout_message.innerHTML = 'Session expired.';
- }
- }
- }
- </script>
- </head>
- <body onload="start_onload()">
- <h1>Example of how can be set timeout done</h1>
- <p> http://stackoverflow.com/questions/11531299/html-session-timeout-in-progress-bar </p>
- <div id="timeout_message" style="position:absolute; left:0; bottom:0; background-color: #ddd; color: red;"></div>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement