Posted on August 16, 2008 - by webmaster
Is there a secret behind file encoding in PHP?
Today i faced a strange warning message when executing a PHP file,
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at file.php:1) in file.php on line 15
Well not the error message, but the reason that produce this message, i have tried to use different solutions to avoid this error:
- Put the session_start() command in the very first line
- Explicit set of session_save_path
- Change the permission (CHMOD 777)
- Reset the php.ini session auto start + Explicit set on the codes
but none of ‘em fix the error. Then i try to use unusual test, changing the file encoding from UTF-8 (i always save my file in UTF-8 encoding) to ANSI, and Booom! the error message gone
.
Didnt really know how the file encoding can cause this error, because i always use UTF-8 and produce the same code and never get this error. Is there any secret of file encoding on PHP?, now you tell me
, because within ANSI i could not produce foregin characters, so i need a better solutions, to kiss this error away and keep the UTF-8 encoding.
Any suggestions guys?

Visit My Website
August 16, 2008
Permalink
Maybe you saved the UTF-8 file with BOM (Byte Order Mark). This adds a byte in the beginning of the file and could produce the error you reported.
Visit My Website
August 30, 2008
Permalink
Not only maybe. I’m shure this was the Problem. I had the same Problem when i was about to switch to UTF-8. No i’m using Notepad++ which supports UTF-8 files without BOM.
Visit My Website
September 1, 2008
Permalink
me either using notepad++, but sometimes using Dreamweaver or PHP designer, still could not find the cause, cos the other files works just fine.
Visit My Website
October 17, 2008
Permalink
Notepad++ version 4 had a bug with encoding and BOM, get Notepad++ 5 and save it without BOM from there.
Visit My Website
June 19, 2009
Permalink
Well, it’s a little too late but this error has nothing to do with encoding. The error “headers already sent” pops when you try to send some metainfo in the header of the page, but the header has already been sent.
You must control the header sending manually. at the begin of you PHP just put, the first instruction of all:
<? ob_start();
And then at the end, or when you want to send the headers, put "ob_end_flush();"
This way you control when to "release" the page to the client.