I've got a logout script that kills all my session data then starts a new session to hold a message for the logged-out user when he's redirected to the login page. I'm getting the following Fatal error (Latest release of RedHat Linux/Apache/PHP):

Fatal error: session_start(): Failed to initialize storage module. in /home/minorgod/public_html/online-courses-test/logout.php on line 17

Here's the suspect code...I'm using my own session handlers with MySQL also.....

$_SESSION=NULL;
setcookie (session_name(), '', (time () - 2592000), '/', '', 0);
session_destroy();
//session_regenerate_id();
session_start();
$_SESSION['message']="You have been logged out.";

The above code caused no errors until I added the session_start() and now it gives me an error.

    straight from the manual...

    Note: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.

    also, session_start() like to be the first line in the PHP script...

      Mmmmmm...no. Thanks for replying, but nothing is being output to the browser besides headers, so that shouldn't affect anything. It shouldn't matter where session_start() is as long as it's called before attempting to access any session vars. You should be able to destroy a session and then start a new one with a new ID and a new cookie, as long as the old one has been properly destroyed and the old cookie deleted. The first session in my code above was started half-way through an included 200+ line config file after declaring custom session handlers, etc. I'm only showing the relevant code here because I'm 100% positive this is where the problem is since the other code has been working fine for months. If I remove the session_start() after the session_destroy(), the code still works fine. I just need to know why I'm getting the error message described in my first post. I've never seen this error before. It has nothing to do with HTTP headers or we'd be looking at a totally different kind of error message.

        what is your session.save_handler set to in your php.ini

          I believe it's either set to "files" or "user", but that's sort of irrelevant since I've defined my own save handlers to save sessions in MySQL. These custom handlers have been working fine, so whatever my php.ini settings are, they let me define my own handlers. I'm starting to suspect that I might need to redeclare my custom handlers before I call session_start() again. Do you think that could be the problem?

            Originally posted by minorgod
            Do you think that could be the problem?

            That could very well be the problem, wasn't sure what else you got going on... Really hard to diagnose session problems sometimes, other than the obvious ones... cuz it's usually a setting or like you have, a custom handler...

              Write a Reply...