Codeigniter error message Cannot modify header information

后端 未结 4 1271
粉色の甜心
粉色の甜心 2021-01-22 13:28

I got this error message when i run my php CodeIgniter project:

A PHP Error was encountered

Severity: Warning

Message: Cannot modi

4条回答
  •  天涯浪人
    2021-01-22 13:56

    You can't display anything before the header function is called. You should not display anything form model or controller to avoid this kind of error. If you want to display something form the controller or model then you should store the output to the buffer instead of sending it to the browser. You can store the output to the buffer using ob_start() function before header() function is called. Then you can do something like this

    if(true)
    {
        header("Location:http://google.com");
    }
    else
    {
       ob_end_flush();
    }
    

提交回复
热议问题