-1

Possible Duplicate:
Use case for output buffering as the correct solution to “headers already sent”
Headers already sent by 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?

Community
  • 1
  • 1
Hiroshi Rana
  • 978
  • 2
  • 9
  • 18
  • 2
    Nope, to avoid the error - just don't send anything before starting session. In programming (and in life as well) it makes sense to fix the roots of the issue, not the consequences – zerkms Jan 31 '13 at 04:19

1 Answers1

3

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.

zerkms
  • 249,484
  • 69
  • 436
  • 539