views:

33

answers:

1

I have a PHP script that reads a file and outputs it to the client. It's a CSS file, so I've used header() to set Content-Type, Content-Length and Cache-Control. If I add a made-up header, I can see it using Tamper Data so it seems that basically it's working (and the file is received fine by the browser). What I don't understand is that I also see a number of other headers (eg. Expires) and and something actually changes my value of Content-Length - presumably because it's Content-Encoding: gzip. In php.ini it has zlib.output_compression = Off so I'm unsure what's jumping in at the last step to modify the headers. Can anyone explain this for me?

Thank you for your time.

+1  A: 

These headers come from the web server. PHP gets called to deliver the content (and any additional headers) but it's the web server that does the delivering, using its own rules and configuration settings.

Pekka
Thank you for the quick response. So it's perfectly acceptable/normal to set minimal headers and let the web server package it into a valid HTTP response?
Jes
@Jes totally depends on what you want to do! Usually, the answer is yes: The web server usually servers healthy default headers. But `content-type` and `cache-control` you may need in certain situations. For example, if you dynamically generate a CSS style sheet in a PHP script ending in .php, you need to send a `text/css` content-type along with it or Firefox won't accept it. It really depends on the situation.
Pekka
Thanks - very helpful.
Jes