FIX: PHP Cannot modify header information – headers already sent (line:1)

Sometimes, you may start to see a PHP error complaining about headers already being sent so headers can’t be modified. This usually happens when you echo content and then called the header() function. While those are easy to fix, some others arent, like when PHP complains about output already being sent on LINE 1 when you know there’s nothing on line 1 except “<?php”. Following is an example error
[cc lang=”html”]====================================
PHP WARNING
====================================
PHP Warning: Cannot modify header information – headers already sent by (output started at /home/www/abcde.php:1) in /home/www/def.php on line 90[/cc]
To fix these stupid errors, here’s a couple of things you can do:

  • Open the file in Dreamweaver and click SAVE AS and UNCHECK the “Include Unicode Signature (BOM)” checkbox
  • Copy the file content and paste it into a new file saving it WITHOUT including unicode signature BOM
UPDATE: PHP version 5.3.8 doesn’t show this error even when there is a BOM character in the beginning of the file. However, older versions of PHP like version 5.1.6 do show the error.
UPDATE 2: Notepad always add the BOM character. Don’t use it. Use Dreamweaver or Notepad++ instead. You’ve been warned!