note 77028 deleted from function.header by tularis
| From: | tularis@php.net | Date: | Fri, 04 Apr 2014 11:29:33 +0000 |
| Subject: | note 77028 deleted from function.header by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199165@lists.php.net to get a copy of this message | ||
Note Submitter: ryanhanekamp at yahoo dot com
----
I strongly recommend the "Live HTTP Headers" plugin for Firefox for any work when manually
setting headers. (Find it in the addons section on mozilla.com) This allows you to see the headers
your PHP script and server are sending, plus Firefox's request headers.
One important thing to note is a conflict with many of the scripts here, including in lasitha dot
alawatta's Excel post just a few below me, is that sending multiple headers of the same type
from your script does not actually cause multiple lines of output to the browser, at least for the
version of PHP5 I'm running, and it's doubtful the browser would process any other than
the last line anyhow.
So sending multiple "Pragma: " or "Cache-Control: " headers results in only the
last one set in your script to actually be sent.
Also, it's already been pointed out, but setting "Cache-Control: Pre-Check=0,
Post-Check=0" does absolutely nothing. I believe only MSIE even uses these values and it
specifically IGNORES both of them when both are set to zero.
I've actually had more trouble trying to encourage caching than preventing it, because PHP
sends "Cache-Control" and "Pragma" headers either always or at least always with
sessions on (and I always have sessions on). The trick is to always send BOTH
"Cache-Control" and "Pragma" because if they conflict it's completely up to
the browser to resolve. And if you have a custom server in PHP like I'm working on right now,
you'll need to sniff for $_SERVER['IF-MODIFIED-SINCE'] and serve up "HTTP/1.1
304 Not Modified" as appropriate.
If you are doing something like this and want to ensure caching of static files, the best way I
found was to give an honest "Last-Modified", set an "Expires:" a reasonable time
in the future (a few minutes through the year 2038, depending on what you're doing), set
"Cache-Control" to "private" or "public", and stay away from
"Max-Age".