Created
November 5, 2015 11:42
-
-
Save gintsmurans/6777b47f5329e708d3f2 to your computer and use it in GitHub Desktop.
Session expire and destroy other sessions
This file contains hidden or 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 | |
const SESSION_EXPIRATION_TIME = 100; // Seconds | |
function session_expire() | |
{ | |
if (empty($_SESSION['last_visit'])) { | |
$_SESSION['last_visit'] = time(); | |
} | |
if ($_SESSION['last_visit'] + SESSION_EXPIRATION_TIME < time()) { | |
session_destroy(); | |
session_write_close(); | |
session_start(); | |
session_regenerate_id(true); | |
} | |
} | |
function session_destroy_id($id) | |
{ | |
// Close current session | |
$current_session_id = session_id(); | |
session_write_close(); | |
// Start session that we need to destroy | |
session_id($id); | |
session_start(); | |
session_destroy(); | |
session_write_close(); | |
// Re-Start current session | |
session_id($current_session_id); | |
session_start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment