Cannot modify header information – headers already sent

Posted on June 17, 2018 at 12:09 pm

Here you will find various solutions to fix this PHP error message:

Cannot modify header information - headers already sent

Solution 1 – UTF-8 without BOM

Make sure the file encoding format of all PHP files is UTF-8 without BOM.

You can use Notepad++ to convert the encoding format of your PHP files.

Solution 2 – Remove blank lines before/after PHP tags

Make sure there are no blank lines sent before the HTML tag:

To fix those blank lines, check all PHP files included/required before showing the page header.

Then make sure there are no spaces or blank lines before <?php and at end of ?>

Each PHP file should start with <?php and end with ?>.

No blank lines should be present before or after those tags, else they are sent to the client.

And thus you would not be able to modify the headers because they’re already set.

Solution 3 – Use CSS files, not <style>…</style>

Inside the HEAD tag, make sure to load the CSS code from .css files.

Do not write it within <style>…</style> tags, else it seems to cause “headers” issues.

In my case, I had to use .css files to fix the “Cannot modify headers” issue.

Solution 4 – Try using ob_start();

Add ob_start(); at the very top of your PHP script.

Then add ob_end_flush(); at the very end of your PHP script.

This would most probably fix any “Cannot modify headers” issues.

Here is an example usage:

<?php ob_start(); ?>
<html>
<!-- Output -->
</html>
<?php ob_end_flush(); ?>

Receive updates via email

Other Posts

Updated Posts