简体   繁体   English

PHP标头未发送到浏览器

[英]PHP headers not being sent to browser

I have quite a strange problem with PHP and Apache on my local testing server. 我在本地测试服务器上的PHP和Apache遇到了一个非常奇怪的问题。 For some reason it keeps stopping sending headers to the browser (I am pretty sure that is the problem anyway). 由于某种原因,它一直停止向浏览器发送标头(无论如何,我很确定这是问题所在)。

It's not a case of the old 'output already sent' as it was working fine, had the problem, went away after I reinstalled Apache and is now back again. 这不是旧的“输出已发送”的情况,因为它可以正常工作,出现问题,在我重新安装Apache之后消失了,现在又回来了。 Sessions also appear to be broken. 会话似乎也中断了。 It also gives no errors for 'headers already sent', plus the code works on the live site. 它也不会给“已发送的标头”带来任何错误,并且代码可在实时站点上正常工作。

It's not the browser either as I tried different browsers and different machines, which exhibit the same problems. 也不是浏览器,因为我尝试了不同的浏览器和不同的机器,它们都表现出相同的问题。

Even something dumb such as <?php header ('Location: http://www.yahoo.com'); ?> 甚至有些愚蠢的东西,例如<?php header ('Location: http://www.yahoo.com'); ?> <?php header ('Location: http://www.yahoo.com'); ?> doesn't work. <?php header ('Location: http://www.yahoo.com'); ?>不起作用。

I am running wampserver (latest version) on Windows. 我在Windows上运行wampserver(最新版本)。 Answers on a postcard. 在明信片上的答案。

Even something dumb such as <?php header ('Location: http://www.yahoo.com'); ?> 甚至有些愚蠢的东西,例如<?php header ('Location: http://www.yahoo.com'); ?> <?php header ('Location: http://www.yahoo.com'); ?> doesn't work. <?php header ('Location: http://www.yahoo.com'); ?>不起作用。

Try with this instead: 尝试与此:

<?php header('Location: http://www.yahoo.com'); exit; ?>

Firstly, check that your PHP.INI has 'display_errors' set to 'On' and while you're at it, make sure 'error_reporting' is set to 'E_ALL & ~E_NOTICE'. 首先,检查您的PHP.INI的“ display_errors”设置为“ On”,并在使用时确保“ error_reporting”设置为“ E_ALL&〜E_NOTICE”。 Without those, you won't see errors even if they occur. 没有这些,即使发生错误也不会看到错误。

Secondly, ensure that you set 'output_buffering' to 'Off' in the same file. 其次,请确保在同一文件中将“ output_buffering”设置为“关”。 Just in case. 以防万一。

Finally, there was mention of checking your Apache log. 最后,提到了检查您的Apache日志。 It's also important to check your PHP error log (which is generally a different file again). 检查您的PHP错误日志(通常又是另一个文件)也很重要。

重新安装修复它,非常奇怪。

If you were using Xdebug on February 2010, it used to have a known issue with generated HTTP headers: 如果您在2010年2月使用Xdebug,它曾经在生成HTTP标头时存在一个已知问题:

This issue is now fixed so either switch to a newer version or remove the extension altogether. 现在已解决此问题,因此可以切换到新版本或完全删除扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM