Skip to content

Instantly share code, notes, and snippets.

@gintsmurans
Created November 5, 2015 11:42
Show Gist options
  • Save gintsmurans/6777b47f5329e708d3f2 to your computer and use it in GitHub Desktop.
Save gintsmurans/6777b47f5329e708d3f2 to your computer and use it in GitHub Desktop.
Session expire and destroy other sessions
<?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