-3

How can I pause a session after a particular time (such as when user is inactive for 30 minutes) without logging the user out?

More specifically, I'd want to know when the user is logged in, when the session starts, and the duration of the session. If the user is inactive for 30 minutes, the session should be paused - but not logged out - and record the amount of "break time." If the user is still inactive for one hour, the session will be terminated and log out.

Note: If the user is active after 30 minutes, the session should restart.

My code is as follows. Can you suggest a better source for me?

include('../config/connect.php');
session_cache_expire( 20 );
session_start(); // NEVER FORGET TO START THE SESSION!!!
$inactive = 3600;
if(isset($_SESSION['start']) ) {
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive){
header("Location:mylogout.php");
}
}
$_SESSION['start'] = time();

if($_SESSION['LOGIN_STATUS'] != true){
header('Location:mylogin.php');
}else{
4444
  • 3,541
  • 10
  • 32
  • 43
Rohan
  • 3
  • 3
  • 3
    *he cant be logout* why torture your users? – Mr. Alien Jul 08 '13 at 19:11
  • Better use cookies or store session ids in database. – hjpotter92 Jul 08 '13 at 19:13
  • if the session is paused, how could a user unpause it? if the unpause is automatic, then what's the point of pausing in the first place? **EVERY** session is by definition "paused" between hits on the server. – Marc B Jul 08 '13 at 19:20

1 Answers1

0

Save the session on database:

$session->update('session',serialize($_SESSION),'userid = '.$userid);

And you can reload:

$_SESSION = unserialize($session->select('userid = '.$userid));

Note: This is a teoric example. Try yourself

Guerra
  • 2,792
  • 1
  • 22
  • 32