Rudie
Rudie

Reputation: 53821

Confused Man Seeking: "Warning: Cannot modify header information"

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!

Upvotes: 3

Views: 191

Answers (2)

Itay Moav -Malimovka
Itay Moav -Malimovka

Reputation: 53597

put flush() after the var_dump

Upvotes: 2

Galen
Galen

Reputation: 30170

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

Upvotes: 5

Related Questions