开发者

PHP output_buffering on/off issue

I have created a PHP application with output_buffering = On.

Now, if i do output_buffering = Off then i have get following error

"Cannot modify header information - headers already sent by ".

How can i remove this error?

What can be the drawback if i uplo开发者_Python百科ad application on live site with output_buffering = Off?


From PHP Tag Wiki:

Q. "Headers have already been sent..."
A. You're outputting content and triggering PHP's default content-type:text/html header before making your own call to header(). There are a few ways this can happen, check for a stray echo or print, whitespace before and after the tags or maybe a Unicode BOM. Consider using output buffering. With many scripts, there is no need to include the ending ?> and the problem is easily fixed by removing the ending ?> tag from your files.

There is also a myriad of duplicates for this.


Send out your headers before any output goes to the browser.

header('Foo: bar');
echo "foo";


If you turn output buffering off, you are not allowed to send any additional headers (this includes cookies e.g.) after you've send any piece of data to the client (namely using echo or some other output function).

You can use headers_sent() to check where you started to output data to the client.


Ensure all header('') tags go right at the top of the script with no white space!

EG:

<?php
header('type of header');
?>

If you really have to do it further down the page you can call ob_start() at the top of the script. Call ob_end_flush() at the end of the script too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜