steven
steven

Reputation: 4875

missing "headers already sent"-warning on output before header

I know there are lots of threads about headers already sent output, but i have a strange effect on my Debian VM (PHP Version 5.3.3-7+squeeze15)

The following code works although it should not work!

<?php
echo "test";
header("Location:http://www.example.com");
?>

Does anybody know why it works and i dont get an "headers already sent warning"?

Upvotes: 2

Views: 193

Answers (2)

RMcLeod
RMcLeod

Reputation: 2581

From the php.ini file comments for the setting output_buffering:

; Output buffering is a mechanism for controlling how much output data
; (excluding headers and cookies) PHP should keep internally before pushing that
; data to the client. If your application's output exceeds this setting, PHP
; will send that data in chunks of roughly the size you specify.

; Turning on this setting and managing its maximum buffer size can yield some
; interesting side-effects depending on your application and web server.
; **You may be able to send headers and cookies after you've already sent output**
; through print or echo. You also may see performance benefits if your server is
; emitting less packets due to buffered output versus PHP streaming the output
; as it gets it. On production servers, 4096 bytes is a good setting for performance
; reasons.

Upvotes: 7

TecHunter
TecHunter

Reputation: 6131

Try flushing after the echo to make it not work

<?php
echo "test";
flush();
header("Location:http://www.example.com");
?>

Upvotes: 2

Related Questions