Tired of not being able to use your browser's Back button without getting those annoying “The page you are trying to view contains POSTDATA that has expired from the cache” warnings all the time? Here's how to fix it.
We need to modify inc/init.php to have it add the “Cache-control: private” header.
Change line 50 in inc/init.php from
if (!headers_sent()) session_start();
to
if (!headers_sent()) { session_start(); header("Cache-control: private"); }
This was tested with an installation of the 2005-09-22e version of DokuWiki.
Starting in release 2006-03-09b, the place to add it looks like this (see below for line numbers):
// init session if (!headers_sent() && !defined('NOSESSION')){ session_name("DokuWiki"); session_start(); header("Cache-control: private"); // Add this line to prevent warnings }
Here is where to add the line for other versions:
Anyone want to explain WHY this works? Apparently “Cache-control: private” means that the local browser can cache the page, but any intermediate proxies are not allowed to cache it. Not sure why that prevents the warning though. Google found this article, but I still don't fully understand. — Erick
PHP sets the default value of the Cache-control header to “private, nocache”, which instructs both the proxies and the browsers to NOT cache the page. The “POSTDATA has expired” warning shows up because the browser can't give the user a cached version, but also can't decide whether it's “secure” to send the POST request again without breaking anything in the web application. By defining the header inside the script, you are taking out the “nocache” part, and thus letting the browser to give the user a cached version of the page when he “hits the back button”. — Eloi Granado
Nice little improvement. We like it. Thanks. — rehan