How to fix "Headers already sent" error in PHP

How to fix "Headers already sent" error in PHP

by adesignguy

Posted on 26/01/2016 14:11:11 | Code


This generally happens because there is something being sent before the output. Functions that modify/send HTTP headers must be invoked before any output is made.

First check the offending file for excess whitespace before any PHP opening tags. This is usually at the beginning of the file.

If all else fails, a workaround is to put

<?php ob_start(); ?>

at the very top of your header.php file and

<?php ob_end_flush(); ?>

at the bottom of your footer.php file. This might fix your problem, although it is a workaround and not a cure.