Is it OK to have ob_start()
in the beginning of all PHP pages?
If I don't do this, I get the "headers already sent" error.
Is it OK to have ob_start()
in the beginning of all PHP pages?
If I don't do this, I get the "headers already sent" error.
It is "ok" but you should really fix your script to not output stuff prematurely and save the output for the end. But you can just change a setting in .htaccess
or the php.ini
the below is the for .htaccess:
php_value output_buffering On
php_value output_handler mb_output_handler
This would be preferred, in my opinion, instead of adding ob_start
to the top of all your scripts.
However, you really should fix the problem at its core. IE: Save output for the end of the script.
you may have white space before at the top of page
This will lead that error "HEADER ALREADY SEND "
No idea about ob_start()
I would say it is okay to do this as a workaround or when simply quickly making your existing script work. In the long run however you should think about redesigning your application so things like this don't happen. In general you should try to completely separate application logic and the output.
© 2022 - 2024 — McMap. All rights reserved.
open_end_clean
itob_end_flush
but u should look for where the header come from – Delob_end_clean
, notopen_end_clean
. :) – Targum