PHP Page redirect problem - Cannot modify header information [duplicate]

巧了我就是萌 提交于 2019-11-30 08:36:30

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!