Welcome Guest, Not a member yet? Register   Sign In
Usage of ob_start() to avoid "header already sent" error
#1

[eluser]goFrendiAsgard[/eluser]
In my application, I can ensure that there is no such a "un-intentional" whitespace or whatever. I don't perform "echo" at controller or model, but there is always "header already sent" error on the log file (Nothing shown in browser).

PS: I load session and input library at both, the model and the controller

This is actually not a big problem, but the error become terrible if I use CLI request.

After browsing a while, I find this answer at stack overflow:
http://stackoverflow.com/a/13783368/755319
It said that I can add ob_start() for output buffering at the beginning of index.php

Code:
<?php
ob_start();
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------

Is is save to do such a thing?
#2

[eluser]TheFuzzy0ne[/eluser]
Does it not tell you where the headers were sent?

You can safely omit the closing PHP tag at the end of a file to avoid this situation.
#3

[eluser]goFrendiAsgard[/eluser]
Okay, BTW this is the solution:
http://stackoverflow.com/a/15272229/755319




Theme © iAndrew 2016 - Forum software by © MyBB