I am using session to store user values.
This code is on top of login.php
:
// If user is logged inn, redirect to index.php
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
header("location: index.php");
exit;
}
This code runs when a user successfully logged in from login.php
:
// Password is correct, so start a new session
session_start();
session_regenerate_id();
$_SESSION["loggedin"] = TRUE;
$_SESSION["name"] = $name;
This code is in the top of all .php pages in my website, for example index.php
:
<?php
// Start session to use session in page.
session_start();
// Redirect if user is not logged in
if (!isset($_SESSION['loggedin'])) {
header('Location: login.php');
exit;
}
?>
I have a page named testphpini.php
to check the phpinfo()
. This is how the session variables looks like:
As you can see, the Local Value for session.gc_maxlifetime has been changed to 28800(8 hours), but still users are having issue being logged out after a short amount of time.
What am I doing wrong? What am I missing?