Friday, July 13, 2018

OB Start before Session Start to Avoid Header Already Sent Error in PHP?











To avoid 'headers already sent' error message can I use obstart before session start in PHP, like below:



// db information here
ob_start();
session_start();



Is this a good practice to use in every PHP project to avoid 'header already sent error' or it is for special cases?


Answer



It's not a good practice.



The only correct solution - is to not send anything before you run session.



It's not for special cases, it's for people who cannot write properly. Treat it as a dirty hack for newbies.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...