To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Problems with PHP headers, fixed.

Ever had problems with PHP saying 'headers already sent' and you cannot find out where? Well this post might help you.
08 Jul 2015 at 16:14

For some time I have been noticing that several error logs across my site have been filled with errors relating to attempted header updates in PHP that are failing.

I found out today what the problem is.

The error for most of them occurs on line 1, and it's because of Aptana Studio saving in UTF with BOM. BOM or Byte-Order-Mark is a single array of characters that is put at the start of a UTF file. The BOM can be seen with a hexeditor such as Notepad++ on Windows or hexdump on *nix machines.

It looks like this:

EF BB BF

Because PHP recognises this as output, it simply leaves it in and therefore PHP flushes the headers and the headers cannot be sent. Don't get fooled by this issue that has had me fooled for months.

Hex Fiend

There is more information here:

http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php

http://ext.raneous.net/post/16512690236/my-utf-8-byte-order-mark-bom-adventure

php
headers
problems
sent
already
byte-code
byte-order-mark