标题不言自明.
我对 PHP 有一些经验,但我不确定 header
函数在 ob_start()
和 ob_end_clean()
之间是如何工作的代码>.
I have a good bit of experience with PHP, but I am not sure how the header
function works between ob_start()
and ob_end_clean()
.
考虑一下:
ob_start();
echo "Some content";
header('X-Example-Header: foo');
echo "Some more content";
$output = ob_get_contents();
ob_end_clean();
echo $output;
header
函数是否会忽略输出缓冲,因此所有标头都会在内容之前发送,因为它是在 header
之后 echo
ed打电话?
Does the header
function ignore the output buffering, and thus all headers get sent before the content because it is echo
ed after the header
call?
还是以其他方式起作用?
Or does it work some other way?
header()
确实忽略了输出缓冲.使用输出缓冲的部分原因是您可以乱序"发送 HTTP 标头,因为响应已被缓冲.一旦发送了任何类型的输出(除非该输出被缓冲),就不能发送 HTTP 标头.
The header()
does indeed ignore output buffering. Part of the reason to use output buffering is so you can send HTTP headers "out of order" since the response is buffered. You can't send HTTP headers once you've sent any kind of output (unless that output is buffered).
这篇关于标头如何与 PHP 中的输出缓冲一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!