Cannot modify header information

This question already has an answer here:

  • How to fix “Headers already sent” error in PHP 11 answers
  • Reference - What does this error mean in PHP? 30 answers

  • I have much easier solution for you - it is simple! Just add this command at the very start of the php source:

    ob_start();
    

    This will start buffering the output, so that nothing is really output until the PHP script ends (or until you flush the buffer manually) - and also no headers are sent until that time! So you don't need to reorganize your code , just add this line at the very beginning of your code and that's it :-)


    before sending any thing to view (text in the browser). check if your model that if id is valid or not . if id is not valid redirect to your error page

    header("HTTP/1.1 301 Moved Permanently");
    header( 'Location: http://examplesite.domain/errorpage' ) ;
    

    No content should be sent to the browser before using php header() redirection. You can try javascript redirection instead if headers already sent.

    if( mysql_num_rows( $qselect ) === 0 )
    {
       echo "<script type='text/javascript'>window.location.href='{http://examplesite.domain/errorpage}'</script>";
       exit;
    }
    

    But I am not sure javascript redirects are search engine friendly

    链接地址: http://www.djcxy.com/p/69394.html

    上一篇: 在php中回显会话变量

    下一篇: 无法修改标题信息