I had a problem handling session in PHP (version 5.2.10). I use the following functions to log in, log out, and verify sessions.
login ()
{
session_set_cookie_params (0);
session_start ();
session_regenerate_id (true);
$ _SESSION ['user_id']
}
validate_session ()
{
session_set_cookie_params (0);
session_start ();
if (isset ($ _ SESSION ['user_id']) === FALSE) {
session_destroy ();
logout ();
header ("Location: login_page");
}
}
logout ()
{
session_set_cookie_params (0);
session_start ();
$ _SESSION = array ();
setcookie (session_name (), '', time () - 3600, '/');
session_destroy ();
}
Each page first calls the validate_session () function call. If the session is invalid, it is redirected to the login page. The login () function is used to create a session for the user. When the user clicks the logout button, the logout () function is called to destroy the session.
Problem: randomly, the logout () function throws a warning:
Warning: session_destroy (): Object object failed
I receive this warning very rarely. For example, from 20-30 calls to the exit, I get it once. Any thoughts?
I am developing on a Windows XP machine.
Update: Sessions are stored in the file system.
Path: C: \ WINDOWS \ Temp
Varun
source share