I get "Session object destruction failed" when I use session_destroy().
session_start();
if(isset($_SESSION['user_id'])){
$_SESSION=array();
if(isset($_COOKIE[session_name()])){
setcookie(session_name(),'',0,"/");
}
session_destroy();
}
What causes this error?
Error:
It's rather trivial, no session
has been startedobject has been comitted, so you can't destroy it.The
@
operator is not always active, e.g. with error reporting functions.Edit:
This error is normally caused when PHP tries to delete the session file, but it can't find it.
In your case with
session_destroy
there is only one place in PHP which causes this. That's when thesession.save_handler
(see as wellsession_set_save_handler
) returnsFALSE
for the destroy action. This can depends which type of save-handler you use, the default one is files. With that one, when thesession.save_path
setting is wrong (e.g. not an accessible directory), this would cause such an error.That depends how the output is created and on PHP configuration.
@
does not always work. For example callbacks registered withset_error_handler
will still receive these messages.