Skip to content

Instantly share code, notes, and snippets.

@vella-nicholas
Created May 11, 2022 10:34
Show Gist options
  • Save vella-nicholas/6f6758239ceb70c9d9fe28c901cd4209 to your computer and use it in GitHub Desktop.
Save vella-nicholas/6f6758239ceb70c9d9fe28c901cd4209 to your computer and use it in GitHub Desktop.
Handy code to use session as cache
<?php
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) {
// last request was more than 30 minutes ago
session_unset(); // unset $_SESSION variable for the run-time
session_destroy(); // destroy session data in storage
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment