views:

319

answers:

3

To allow caching a PHP generated file, I want to make sure, that the 'Pragma: no-cache' header is not set. However, how do I delete a possibly already set header?

That is, it could be possible, that somewhere in the code someone wrote header('Pragma: no-cache'); and now I want to make sure, the header is not sent.

Is it sufficient to do this:

header('Pragma:');

or is there something like delete_header() (which would, apparently, be undocumented or well-hidden)?

+1  A: 

You can override a previously set header by passing a second argument to header():

void header ( string $string [, bool $replace = true [, int $http_response_code ]] )

Check the manual for header()

pix0r
I know that, but the question is, if this is sufficient, i.e., if providing just 'Pragma:' for header() will erase it from the list of sent ones.
Boldewyn
+4  A: 

header_remove() since php 5.3

chris
Cool, thanks. It's a pity, that the PHP boys thought of this just recently (after all, HTTP handling is a core application area of PHP).
Boldewyn
A: 

The 'pragma' headers behaviours are not defined by the spec - despite the widely held believe that sending a 'Pragma: No-cache' header will have some effect on the browser, in fact it is almost universally ignored (and is never returned by any php installation I've used).

To tell the browser NOT to cache content is done via an expires header with a date in the past, a Cache-Control header with a no-cache value, or (if you want to be sneaky) by a 'Varies: Date' header. In the absence of any of these types of header the client must not cache the page.

So, conversely, if you want a page to be cacheable, set the expires and cache-cntrol headers.

C.

symcbean