Preventing caching in php

Sometimes when you have php programs that render data from databases, after updating the data from a webpage the server will cache the results from before the update effectively showing wrong data.

We found this to be especially problematic with MSIE. Internet Explorer seems to try to re-use the data when we navigate between jquery tabs in IE.

To fix this we made the programs that render the tab content send these HTTP headers to prevent cacheing:

//Set no caching
header(“Expires: Mon, 28 Jul 1997 05:00:00 GMT”);
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”);

This seems to solve the problem.

This entry was posted in Uncategorized. Bookmark the permalink.