且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP重定向在服务器上不起作用

更新时间:2023-08-22 22:14:16

ob_*

<?php

ob_start();

//Rest of your code

ob_end_flush();
?>

更新:这就是我建议使用 ob_* 函数的原因.我从 brian.moonspot.net 复制的

Updated: Here is the reason i suggested ob_* functions. I copied it from brian.moonspot.net

ob_start 的工作原理

那么,ob_start 有什么帮助呢?ob_start 中的 ob 代表输出缓冲.ob_start 将缓冲输出 (HTML),直到页面完全完成.页面完成后,将发送标头,然后发送输出.这意味着对 setcookie 或 header 函数的任何调用都不会导致错误,并且会正确发送到浏览器.您确实需要在任何输出发生之前调用 ob_start.再开始输出就晚了.

So, how does ob_start help? The ob in ob_start stands for output buffering. ob_start will buffer the output (HTML) until the page is completely done. Once the page is completely done, the headers are sent and then the output is sent. This means any calls to setcookie or the header function will not cause an error and will be sent to the browser properly. You do need to call ob_start before any output occurs. If you start output, it is too late.