Kamis, 13 Oktober 2011

Warning: Cannot modify header information - headers already sent

Warning: Cannot modify header information - headers already sent happen if there is any output appear before Header. Below are 3 common factors that will cause the warning :

Factor 1 : There is spacing before or after php tag, the spacing will appear before header, so the warning will appears. For example :

Solution : Delete the spacing before <?php


Factor 2 : The included file is above header, and the included file has html output. For example :

If connection.php has html output, then the warning will appears.
Solution : Move the included file code, put it below </head>.


Factor 3 : You set $_SESSION['username'] = $username; before header('Location: http://localhost/plekz/home.php');
Solution : You can add <?php ob_start();?> on the most top of page to buffer the output. When output buffering is active, no output is sent from the script (other than headers), instead the output is stored in an internal buffer. You can add <?php ob_flush(); ?> at the most bottom of page to clear away the contents of buffer.

Tidak ada komentar:

Posting Komentar