Fix Strange “Headers already sent by” in Line 1 PHP File

“Cannot modify header information – headers already sent by” error is most common PHP error happen when we develop a web application. Usually when we want to redirect or send cookie. I used to get that warning a lot long time ago. But since i standardize my PHP code, it doesn’t happen for a while now, until last night.

Yesterday night i was fixing somebody else code and audit the performance as well as the security. But when testing it, i got very strange error, the error was “Headers already sent by” at line 1. I open the file and see at the line 1, it was nothing there, it is just a php open tags, and nothing else.

It confuse me for 1 hour until i finally got the answer from this stackoverflow. The problem is there is a white space unseen character before the oepn php tags. To check it i’m using Notepad++ with plugin called Hex Editor. And i found out there is invisible character at the beginning of the file.

I clean it, check every file and voila, everything works like a charm. So if you found any strange errors, and come to this article, it worth to check it out.

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.