Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Problems with PHP headers, fixed.

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

Posted in Tech talk
php
headers
problems
sent
already
byte-code
byte-order-mark
Comments
Powered by DASH 2.0