0

I'm developing an application that utilizes PDFLib to serve my users dynamic PDF files summarizing their accounts and need to ensure that these pages are not being cached (some sensitive data is passed, and I can't have that stored in cache for security reasons).

I have tried using the following code:

Header("Expires:-1");
Header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
Header("Cache-Control: no-store, no-cache, must-revalidate");
Header("Cache-Control: post-check=0, pre-check=0", false);
Header("Pragma:no-cache");

First of all, I have no surefire way of testing that IE7 is not caching the page, so my first question is "how do I test to ensure that my no-cache headers are working?"

Secondly, after I added these lines to my code, the PDF ceased displaying in IE7. When I remove the lines, it works fine. Anyone have any ideas on how to avoid this behavior?

Thanks in advance!

Edit: The first question has been answered; I should have asked them separately. My second question of "How do I avoid IE7's behavior of not rendering my PDFLib page when the no-cache headers are sent?" is still active.

Matt
  • 6,993
  • 4
  • 29
  • 50
  • 1
    You seem to set two `cache-control` headers. Is the second overwriting the first? – starbeamrainbowlabs Jul 24 '12 at 14:39
  • @starbeamrainbowlabs no, the second parameter of the second cache-control header ensures that the first cache-control header doesn't get overwritten. – Matt Jul 24 '12 at 16:54
  • Yeah, I had to look it up in the PHP documentation when I first saw the snippet (from a google search). It appends the values to the header (end-result being equivalent to writing Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0") http://php.net/manual/en/function.header.php – Matt Jul 24 '12 at 17:56
  • I should check the docs before commenting ;) – starbeamrainbowlabs Jul 24 '12 at 17:57
  • It's always my second instinct, too. I tend to ask, then look it up. I don't know why that is. – Matt Jul 24 '12 at 17:58
  • I'd like to know why people have down-voted this question. It seems to me that it follows all the guidelines set forth in [this article](http://stackoverflow.com/questions/how-to-ask). – Matt Aug 02 '12 at 15:31
  • I thoroughly agree with you. You should be forced to give a reason for downvotes. – starbeamrainbowlabs Aug 02 '12 at 15:43
  • 1
    @starbeamrainbowlabs or at least +1 someone else's comment. – Matt Aug 02 '12 at 15:44

2 Answers2

1

To check if the page is cached, change it and refresh. Note that the Expires header should contain a date, so the value of -1 is invalid. Try using a date in the past instead.

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
  • If I'm not mistaken, "-1" evaluates as an invalid date, which is automatically assumed by the browser to be "a date in the past," correct? – Matt Jul 24 '12 at 14:01
  • Also, yes, that's the obvious answer; I was wondering if there were any developer tools out there (for IE7 specifically) so that I don't have to go through the chain of command x number of times to keep committing & pushing my code to the testing server just to test to see if my page isn't being cached. – Matt Jul 24 '12 at 14:03
  • @Matt Probably, although I've always used far future dates and I think this is likely to have bugs. If you want to test the specific behaviour of IE, you'll have to load up the page in IE. – Michael Mior Jul 24 '12 at 14:04
  • That's what I figured; I just wanted to try to avoid the circlejerk of "modify, commit, code-review, push, test, repeat." – Matt Jul 24 '12 at 14:15
  • @Matt No local development environment? :( – Michael Mior Jul 24 '12 at 22:16
  • of course I have a development environment, but I can't test in a vacuum - we develop on Windows boxes, and deploy on Linux. – Matt Jul 25 '12 at 12:59
  • When I said development environment, I mean an environment running roughly the same stack as production servers. – Michael Mior Jul 25 '12 at 13:10
  • my company has a strict process to get code on the testing server and it takes awhile to get it up there, that's all. – Matt Jul 25 '12 at 13:50
0

I actually found Debug Bar http://www.debugbar.com/download.php for IE 7 that shows me all the headers and caching information. I use the HTTP(S) tab, select my document and view "Info & Cache" below. Really easy once I got the hang of it.

Matt
  • 6,993
  • 4
  • 29
  • 50