user1725969
user1725969

Reputation: 3

Non caching page

After 30 minutes the user should get logged out, but it seems the cache is keeping the user online for a couple of pages/clicks...

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
    session_destroy();
    session_unset();
}

$_SESSION['LAST_ACTIVITY'] = time();

// regenerates the session ID periodically to avoid attacks on sessions
if (!isset($_SESSION['CREATED'])) {
    $_SESSION['CREATED'] = time();
} else if (time() - $_SESSION['CREATED'] > 1800) {
    session_regenerate_id(true); 
    $_SESSION['CREATED'] = time();
}

$ts = gmdate("D, d M Y H:i:s") . " GMT";
header("Expires: $ts");
header("Last-Modified: $ts");
header("Pragma: no-cache");
header("Cache-Control: no-cache, must-revalidate");

Upvotes: 0

Views: 40

Answers (1)

Jens Wegar
Jens Wegar

Reputation: 4862

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
    session_destroy();
    session_unset();
}

this part seems to have a typo where one of the parenthesis after 1800 should instead be in front of the "greater than" sign:

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY']) > 1800) {
    session_destroy();
    session_unset();
}

Upvotes: 1

Related Questions