dongnai3960 2015-02-11 08:30
浏览 62

尽管输出已经发送,但正在发送标头

For what I know is it is not possible to send HTTP headers after your output has been sent and only way to workaround is to use output buffering

But my PHP script is able to send headers even after output is sent. here is my code

Text output already sent
<?php
header('Location: test2.php');
die();
?>

Why is this code not giving error for "HTTP headers already sent" Is there another way to turn output buffering on?

EDIT:

I am running it on my localhost using wamp

No files are included in the above code

I just noticed outbut_buffering directive in phpinfo() which is set to 1 But when I check it in php.ini file it is set to Off

  • 写回答

3条回答 默认 最新

  • douzhaiya3968 2015-02-11 08:44
    关注

    You are right, this should not work.

    First, are you sure the headers are written, or do you simply wonder why there is no error message shown? Maybe error reporting is turned off? In that case try to increase the error reporting level:

    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    

    Remove this from your code when you're finished debugging. Errors should be logged to a log file and never be shown in productive environment!

    Also, check if the header is really sent. You can do that with wget for example:

    wget -S http://example.com/
    

    or curl:

    curl -v http://example.com/
    

    You can as well see the HTTP headers in Chromes developer console. In other browsers most probably too.

    If the header is really sent, then there probably is some magic regarding output buffering in place. Are you running this locally or on a remote host? If this is not your host, it might be the provider has set this up. PHP has a feature to automatically prepend and append custom code. Check the php.ini settings for auto_prepend_file and auto_append_file. There could be some ob_start() etc. hidden. You can see all PHP settings by calling phpinfo() or one specific with ini_get().

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程