Created
May 11, 2022 10:34
-
-
Save vella-nicholas/6f6758239ceb70c9d9fe28c901cd4209 to your computer and use it in GitHub Desktop.
Handy code to use session as cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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