I am having problem in session handling in PHP(version 5.2.10). I am using the below mentioned functions for login, logout and validating 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(); }
Every page first makes a call to validate_session() function. If session invalid it redirects to the login page. login() function is used for creating the session for the user. When user clicks logout, the logout() function is called to destroy the session.
The problem is: randomly the logout() function throws the warning:
Warning: session_destroy(): Session object destruction failed
I am getting this warning very infrequently. Like out of 20-30 calls to logout, I get it once. Any thoughts?
I am developing on a windows xp machine.
Update: The sessions are stored in file-system.
Path: C:\WINDOWS\Temp
debug_print_backtrace()
to the logout function, and keep track of the output then compare the outputs, if there a difference, its likely the different call path that's producing your error. (see php.net/manual/en/function.debug-print-backtrace.php) – Glen Fletcher