I've been doing some searching, and I haven't been able to find any way to unset a header from php...

I'm trying to prevent the server from automatically putting in the "Content-Encoding: gzip" header since it is in fact incorrect. Instead, I would take care of this myself so that "Transfer-Encoding: gzip" is used for browsers which actually follow the standard correctly (apparently only Opera, but nonetheless).

    Description
    bool headers_sent ( [string &$file [, int &$line]] )

    Checks if or where headers have been sent.

    You can't add any more header lines using the header() function once the header block has already been sent. Using this function you can at least prevent getting HTTP header related error messages. Another option is to use Output Buffering.
    Parame

    Maybe in the manual comments you can find something.
    At least it is possible to check for if headers were sent
    [man]headers_sent[/man] [man]headers_list[/man] [man]header[/man]
    [man]ob_start[/man]

      Maybe you can send a new header
      with your transfer encoding?

      there is a setting in php.ini - that you can change in .htaccess or in your php page
      for example with function [man]ini_set[/man]

      zlib.output_compression boolean/integer

      Whether to transparently compress pages. If this option is set to "On" in php.ini or the Apache configuration, pages are compressed if the browser sends an "Accept-Encoding: gzip" or "deflate" header. "Content-Encoding: gzip" (respectively "deflate") and "Vary: Accept-Encoding" headers are added to the output. In runtime, it can be set only before sending any output.
      
      This option also accepts integer values instead of boolean "On"/"Off", using this you can set the output buffer size (default is 4KB).
      
          Note: output_handler must be empty if this is set 'On' ! Instead you must use zlib.output_handler. 

      Predefined Constants

      The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

      FORCE_GZIP (integer)

      FORCE_DEFLATE (integer)

      http://php.net/manual/en/ref.zlib.php#ini.zlib.output-compression
      http://php.net/manual/en/ref.zlib.php

      ):

        By default a header created by the [man]header/man function will replace any similar pre-existing header, unless you set the optional 2nd parameter to FALSE.

          Yeah, I've definitely been doing a lot of reading. Unfortunately I like to nit-pick to be as standards-compliant as possible.

          I know it is being sent (I am using Live HTTP Headers extension for Firefox).

          I can send the Transfer-Encoding as well, but it would still be wrong. That would in effect be saying: "This document is a gzip-encoded file that was encoded again for Transfer"

          I'm not really sure if Apache of PHP is adding the header though (I am using Apache 2.2.6 and PHP 5.2.4). I enabled gzip by loading mod_deflate and setting zlib.output_compression = on in php.ini

            NogDog wrote:

            By default a header created by the [man]header/man function will replace any similar pre-existing header, unless you set the optional 2nd parameter to FALSE.

            Your right, I forgot I already tried to unset it that way. It didn't work, but I guess that could have been because PHP is not the one setting it... so I just tried unsetting a different header that I was setting with PHP and it worked... so now I know for sure it is Apache that is setting the Content-Encoding header...

            Anyone happen to know where I might change this setting in Apache? (I don't see anything about it in httpd.conf)

              dirTdogE wrote:

              Anyone happen to know where I might change this setting in Apache? (I don't see anything about it in httpd.conf)

              This is the solution I would suggest, since it's really the only "solution" - having PHP fix Apache's mistake isn't a solution, it's more of a workaround.

              In httpd.conf, look for lines that say "AddEncoding" and comment them out if you don't want Apache automatically compressing things.

                Yeah, I know that. In the beginning I didn't know which was setting it.

                The only such lines I found are:
                AddType application/x-compress .Z
                AddType application/x-gzip .gz .tgz

                I don't think that's what I am looking for. Thanks for the suggestion.

                  Is it only PHP files that you see this compression header being sent? If so, it may in fact be a PHP directive.

                  Check the values for output_handler and zlib.output_compression in phpinfo().

                    zlib.output_compression is set to on... I do want gzip compression, I just do not want the header to be set automatically. Any ideas? (I'd rather not use ob_start('ob_gzhandler').)

                      dirTdogE wrote:

                      Any ideas?

                      Turn off zlib.output_compression - you can still use it anytime you want.

                        Write a Reply...