Jump to content
Larry Ullman's Book Forums

Session_Start Gives Header Already Sent Error


Recommended Posts

Hi there guys and gals. I'm busy uploading my site and during the development process I've relied quite heavily on Larry's book. I do seem to have a problem now that it is uploaded however. It gives me these errors:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /public_html/index.php:1) in /public_html/mvc/controller/system/config.php on line 54

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /public_html/index.php:1) in /public_html/mvc/controller/system/config.php on line 54

 

I have looked on Google but the only solution I'm able to find is that something is being sent to the browser before the session is started. I assume that this might be the solution but for the life of me I'm not able to determine where the problem is. session_start is in my config file just like Larry did it. I have however built my own page construct function to easily put together all of my pages consisting out of a couple of includes. The first thing that this function does is require my config file (so this is also according to my knowledge the first thing done on the page).

 

My site worked perfectly on a local server and didn't have this problem but now that I'm going live I suddenly encounter this. None of the includes on the page incllude the config file on their own so it really is only included once.

 

I would really appreciate it if somebody could just give me some help here or just maybe point me in the right direction?

 

Thank you in advance,

Hermann.



Link to comment
Share on other sites

I have placed session_start at the very start of my config file as well but no luck. On index.php line one there is no whitespace and the only thing there is my opening php tag. I have tried to remove session_start from my config file and place it at the very top of my page specific script but still no luck. Is there a way that.

Link to comment
Share on other sites

You could try using output buffering. Anything that your scripts or included scripts send to the browser will actually be put in a temporary memory i.e. buffer and only sent to the browser at your behest. The nice thing about buffering is that functions like header and session_start do not get put into the buffer and still work as intended.

 

Look up the functions ob_start(), ob_end_flush() and ob_end_clean().

Link to comment
Share on other sites

I have tried this but doesn't seem to me like I'm getting it to work. I have done this interesting experiment: I've placed an echo statement at the beginning of my config file as well as next to my session_start function. The "Here config starts" is above the error while the "here session starts"is echoed just beneath the error. when I moved the session to above the"Here config starts, both the session message and config start message moved to below the error message. Don't know if this makes more sense to somebody else than it does to me!

Link to comment
Share on other sites

Another thing that might help, is that this problem arises on all of my pages. So the problem is not on my index page. I've really tried everything oncluding moving session_start to the beginning of different files, checking for whitespace in files etc.

Link to comment
Share on other sites

 Share

×
×
  • Create New...