According to the code snippet you have pasted here, your variable $_SESSION['login_user']
is never set:
<?php
session_start();
if (isset( $_SESSION['login_user'] ) && (time() - $_SESSION['login_user'] > 1800)) { // 30 minutes
session_unset();
session_destroy();
} else if (!isset( $_SESSION['login_user'] ) ) {
header("Location: login.php");
exit();
}
?>
You can have it working by assigning a value to it, in this case time()
. Try adding this line in your code after verifying $_SESSION['login_user']
is not set:
$_SESSION['login_user'] = time();
That way you can actually check when user has previously logged in and compare it with last 30 minutes as in:
time() - $_SESSION['login_user'] > 1800
You would have something like this:
<?php
session_start();
if (isset( $_SESSION['login_user'] ) && (time() - $_SESSION['login_user'] > 1800)) { // 30 minutes
session_unset();
session_destroy();
} else if (!isset( $_SESSION['login_user'] ) ) {
$_SESSION['login_user'] = time(); // <-- New line added
header("Location: login.php");
exit();
}
?>