>  기사  >  백엔드 개발  >  说好的header()前面不能有输出的呢?

说好的header()前面不能有输出的呢?

WBOY
WBOY원래의
2016-06-06 20:46:381112검색

看手册上说header()调用之前,前面不能有任何输出,但是我测试发现,完全可以有呀?我空了,还多,还是可以执行。那为什么最新版的手册一直都还没更新呢?http://www.php.net/manual/en/function.header.php
我是这样写的

<code class="lang-php">

111
<?php /* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
</code>

回复内容:

看手册上说header()调用之前,前面不能有任何输出,但是我测试发现,完全可以有呀?我空了,还多,还是可以执行。那为什么最新版的手册一直都还没更新呢?http://www.php.net/manual/en/function.header.php
我是这样写的

<code class="lang-php">

111
<?php /* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>
</code>

你没碰上并不一定就是不存在,眼见不一定为实。

http://segmentfault.com/q/1010000000377390

赞楼上的,是因为缓冲区在脚本执行完才输出,此时你立刻刷新,必须出错。

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.