困惑的人寻求:“警告:无法修改标头信息”

发布于 2024-11-03 14:48:37 字数 1557 浏览 1 评论 0原文

我非常想看到 PHP 警告“无法修改标头信息”。为什么?因为它是明智的。您不应该能够在正文之后发送标头。

但我可以!!如果我在控制器中调试某些变量并且之后没有立即退出,则脚本只会重定向到下一页:一切都“顺利”,并且我看不到我的变量转储。

在 PHP 中我可以在哪里配置(?)它不缓冲输出?或者是什么导致了这种奇怪的行为!

需要明确的是:我确实想要 PHP 警告,但我想要重定向 header('Location: ...')去工作。

我很确定在我以前的(本地)服务器(都是 W XP)上它确实抛出了输出/标头警告...

编辑
为了说明这一点,用最基本的代码(我没有字面上使用,但间接地它是相同的):

$form->validate($_POST);
var_dump($form->errors); // !!
if ( $form->noErrors ) {
  header('Location: '.$form->redirectUrl);
  exit;
}

答案
@Heandel 错误报告就是一切(包括通知和弃用等)。不过没关系:无论错误显示如何,发送标头都应该是不可能的。

@tandu我正在使用我自己的框架,但这也不重要。

@ceejayoz 我的代码中没有一个 ob_start 。我不使用它。 (模板 ngin 使用它,但模板不会在回发中触发。)

@Itay Moav 我不在共享主机中。我正在 Windows XP SP2 上本地处理 PHP 5.3.0 (WAMP)。在我的网络服务器(VPS)上,这种情况不会发生:我收到一个不错的 PHP 警告。

更新
感谢

来自 php.ini 的 Galen:

; Note: Output buffering can also be controlled via Output Buffering Control
;   functions.
; Possible Values:
;   On = Enabled and buffer is unlimited. (Use with caution)
;   Off = Disabled
;   Integer = Enables the buffer and sets its maximum size in bytes.
; Note: This directive is hardcoded to Off for the CLI SAPI
; Default Value: Off
; Development Value: 4096
; Production Value: 4096
; http://php.net/output-buffering
output_buffering = On

将其Off 成功了。我不想要自动输出缓冲。谢谢!

I'm very much wanting to see the PHP warning "Cannot modify header information". Why? Because it's sensible. You shouldn't be able to send headers after body.

But I can!! If I debug some vars in a controller and don't exit immediately afterwards, the script just redirects to the next page: all goes 'well' and I don't get to see my var dumps.

Where in PHP can I configure (?) that it doesn't buffer output? Or whatever it is that enables this strange behaviour!

Just to be clear: I DO want the PHP Warning and I DON'T want the redirect header('Location: ...') to work.

I'm pretty sure on my previous (local) server (both W XP) it did throw the output/header Warning...

edit
To illustrate, with the most basic code (that I don't literally use, but indirectly it's the same):

$form->validate($_POST);
var_dump($form->errors); // !!
if ( $form->noErrors ) {
  header('Location: '.$form->redirectUrl);
  exit;
}

answers
@Heandel Error reporting is everything (incl notices and deprecated etc). Shouldn't matter though: sending headers should be impossible no matter the error display.

@tandu I'm using my own framework, but that shouldn't matter either.

@ceejayoz There's not a single ob_start in my code. I don't use it. (The template ngin uses it, but the template isn't trigger in postback.)

@Itay Moav I'm not in a shared hosting. I'm working locally on PHP 5.3.0 (WAMP) on Windows XP SP2. On my webserver (a VPS) this doesn't happen: I get a nice PHP Warning.

UPDATE
Thanks Galen

From php.ini:

; Note: Output buffering can also be controlled via Output Buffering Control
;   functions.
; Possible Values:
;   On = Enabled and buffer is unlimited. (Use with caution)
;   Off = Disabled
;   Integer = Enables the buffer and sets its maximum size in bytes.
; Note: This directive is hardcoded to Off for the CLI SAPI
; Default Value: Off
; Development Value: 4096
; Production Value: 4096
; http://php.net/output-buffering
output_buffering = On

Turning it Off did the trick. I want NO automated output buffering. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧情别恋 2024-11-10 14:48:37

在 php.ini 文件中找到 output_buffering 并确保将其设置为 0

http://us.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering

In the php.ini file locate output_buffering and make sure it's set to 0

http://us.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering

她比我温柔 2024-11-10 14:48:37

flush() 放在 var_dump 之后

put flush() after the var_dump

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文