PHP error: Cannot modify header information – headers already sent [duplicate]
Solution 1:
You cannot use header()
once text has been output to the browser. As your header.php
include presumably outputs HTML, header()
cannot be used.
You can solve this in a couple ways:
- Move the if statement above the header include (this won't work, as you've indicated in comments that
header.php
sets the uid session and other vital stuff). - Call
ob_start()
at the top of the script to buffer the output.
Solution 2:
If the header.php file "has the banner", then it is presumably outputting some HTML content to the page.
You can't issue HTTP headers after you have outputted content.
Solution 3:
You cannot send any headers after sending any other content. A very likely culprit is extra whitespace after your closing ?>
tag in your header.php. It's generally a good practice to omit the closing tag entirely in any script-only php files.
Your error should tell you exactly what line (and what file) is sending the output.