Reputation: 3200
Php provides function session_write_close
. I want to check if session has been closed. session_id()
still returns value.
session_start();
//
// Some code there
//
session_write_close();
//
// Some code there
//
if( /*is session write closed?*/)
echo 'Session closed';
else
echo 'Session still opened';
Upvotes: 1
Views: 509
Reputation: 95151
All you need is
session_start();
session_write_close();
var_dump(sessionStatus()); // this would return false
And
session_start();
var_dump(sessionStatus()); // true
Function Used
function sessionStatus() {
if (function_exists('session_status')) {
return (session_status() == PHP_SESSION_ACTIVE);
}
return defined('SID');
}
Upvotes: 2
Reputation: 20753
If you have PHP version 5.4.0 or greater, you can use session_status().
Upvotes: 1