Skip to content

Instantly share code, notes, and snippets.

@un1ko85
Created September 11, 2013 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save un1ko85/6522668 to your computer and use it in GitHub Desktop.
Save un1ko85/6522668 to your computer and use it in GitHub Desktop.
delete session file
<?php
session_start(); // start the current/old session (loads the $_SESSION variables)
$base_name = '/sess_'; // the base name for the session data files
$old_sessionid = session_id(); // get the current/old id
$_SESSION['test'] = 123; // some test data
session_regenerate_id(); // generate a new id and a new data file
$new_sessionid = session_id(); // get the new session id to store in the user table for the current visitor
session_write_close(); // close (release) the old (and the new) session data file (php apparently doesn't close the old file when the id is regenerated)
unlink('c:' . ini_get('session.save_path') . $base_name . $old_sessionid); // delete the old session data file
session_start(); // restart the current/new session
// show the old/new session id
echo "Old Session: $old_sessionid<br />";
echo "New Session: $new_sessionid<br />";
print_r($_SESSION); // dump any session data
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment