0

What can be used instead of ob_start("ob_gzhandler"); which is causing PHP Warning: Cannot modify header information - headers already sent in Unknown on line 0?

Some, as I believe, related and/or helpful questions asked before:
"Unknown" PHP error - what is that supposed to mean?
PHP warning: headers already sent in Unknown

Community
  • 1
  • 1
Sarah
  • 281
  • 3
  • 7
  • 13

3 Answers3

2

What worked for me (finally) was to put zlib.output_compression in php.ini and set it to ON, successfuly replacing ob_start("ob_gzhandler");

Sarah
  • 281
  • 3
  • 7
  • 13
0

Just put ob_start("ob_gzhandler") at the start of the chain of PHP statements. If PHP emits that warning it means this call isn't at the start.

user562374
  • 3,817
  • 1
  • 22
  • 19
0

If you just want some alternatives, you could set in your php.ini:

zlib.output_compression = On

http://www.php.net/manual/en/zlib.configuration.php

Or in .htaccess if your PHP runs as an Apache module:

php_flag zlib.output_compression On

Here you can use the <Files> or <FilesMatch> directive to limit compression to the files you want.

Actually you can set this property in your PHP script too, but I don't think that it will work: ini_set('zlib.output_compression', 'On')...


Debug question: If you set header('X-something: x'); before ob_start(), does the header() function cause the same error?

Floern
  • 33,559
  • 24
  • 104
  • 119