1

I keep getting timed out between page requests. Sometimes it seems to work, others it doesn't. Can't seem to see a pattern or reason. I'm using the following code at the top of each page and setting $_SESSION['start'] when I validate and log a user in.

<?php 
session_start();
$inactive = 86400;
if(isset($_SESSION['start']) ) {
$session_life = time() - $_SESSION['start'];
if($session_life > $inactive){
    header("Location: login/logged_out.php");
}
}
$_SESSION['start'] = time();

$isLoggedIn = isset($_SESSION['first_name']) && isset($_SESSION['username']);

$_SESSION['url'] = $_SERVER['REQUEST_URI'];
?>

What am I doing wrong and how can I keep users logged in? Do I have to set a cookie? Or is it that the default session expiry time in PHPINI file is lower than the one I set and therefore timing me out. Any Idea how I can override this and keep users logged in for the time that I specify. This is beginning to drive me a little crazy.

I've seen also that using ini_set("session.cookie_lifetime","86400"); might work?

Any help would be very welcome.

Zbigniew
  • 27,184
  • 6
  • 59
  • 66
user1022772
  • 651
  • 3
  • 14
  • 29

0 Answers0