CodeIgniter Forums
Session and headers sent problems :( - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Session and headers sent problems :( (/thread-2726.html)



Session and headers sent problems :( - El Forum - 08-21-2007

[eluser]chobo[/eluser]
I'm trying to get my new version of my site to work, but I'm running into problems with headers and session. This probably has something to do with me being on a shared host because I never have these problems on my test computer.

I made my own session wrapper library, it's very simple and when I run the init() function to start the session, it triggers the "headers already sen" error. I'm not sure how to get my session to run before the server sends it's headers. Any help is appreciated, thanks

Code:
/*
    *    Check if session has been started and if header have been sent
    */
    private function init()
    {
        if (! isset($_SESSION))
        {
            if (headers_sent())
            {
                trigger_error ('Session was not started before headers sent');
            }
            else
            {
                session_start();
            }
        }
    }



Session and headers sent problems :( - El Forum - 08-21-2007

[eluser]Michael Wales[/eluser]
Make sure there isn't any whitespace being sent prior to the session_start() function (spaces at the top/bottom of files that are previously loaded).


Session and headers sent problems :( - El Forum - 08-21-2007

[eluser]chobo[/eluser]
I actually ran into that header problem as well, thanks Whales Smile. Well it took about three and a half hours to get it all working, but it's finally up and running in Codeigniter Smile For the session problem I fixed it by placing ob_start() at the top of all my front controller files (I have two), and an ob_end_flush() at the end. God, what a nightmare and this was with a couple of hours of prep on top of it...


Session and headers sent problems :( - El Forum - 10-03-2007

[eluser]birkof[/eluser]
Same problem here, solved in chobo's way. Thanks