Monday, January 3, 2011

Session Problem in PHP

Problem:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\iiucweb\filename.php:42) in C:\xampp\htdocs\iiucweb\filename.php on line 70

Solution:

Move the session_start() function as first line output in the page.

To use cookie-based sessions, session_start() must be called before outputing anything to the browser.


Make sure you have nothing that outputs to the browser before those lines and delete any unessasary whitespace from that code up. That error means you outputted something to the browser before line 40 and then tried to use a header value that can't be sent because of course the header had already been sent before line 40.