How to make PHP session expire after X minutes
Posted: 07 Jan 2015, 08:17
In "login.php" it is set a session ID for the logged user. Something simple:
In "index.php" I check if the $_SESSION['user_id'] exists, and display content according to user logged or not.
Now, how can I make the $_SESSION['user_id'] expire after 30 minutes?
Code: Select all
<?php
session_start();
// check login data received from a form ..
if($okdata === true) {
$_SESSION['user_id'] = $uzer;
header("Location: index.php");
}
else {
echo 'Incorrect name or password';
}
Code: Select all
<?php
session_start();
if(!isset($_SESSION['user_id'])) {
echo 'User not logged';
}
else {
echo 'User logged';
}