Jump to content

How do I prevent "Back" from rebuilding dynamic PHP page?


david.marks

Recommended Posts

When I click "Back" in the browser, my PHP page is rebuilt from scratch. 

This clears any form variables and unnecessarily hits the database.  Why isn't the page being cached and simply reloaded?  I fear that I'm missing something obvious.

Can anyone offer any tips?
In general, it depends which browser you use. Both Opera and Firefox cache previous page views (mainly because it makes browsing much quicker).

If you want to implement a way to force all users to cache 'back button' page views, you're in for a rocky road, since users can control their own cache.
You can stop this easily with a number of ways with php, at the very top of the page put down
VERY TOP OF THE PAGE

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
?>
With this you never have to worry about caching of that page again.
[code]<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>[/code]
that'll do it in asp just as a note.
[code]<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">[/code]
That will do it for the most part in the form of html, but it's not guaranteed.
[code]header("Expires: Mon, 26 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");[/code]
And that is a more powerful php version of it, again but this will do what the top script does, as well as preventing dynamic data in flash from caching as well.
[quote [email protected] link=topic=101155.msg400043#msg400043 date=1153346781]
<?php
header("Cache-Control: no-cache, must-revalidate");
?>
With this you never have to worry about caching of that page again.
[/quote]

[quote]
Why [b][i]isn't[/i][/b] the page being cached and simply reloaded?
[/quote]

Verry nice and informative. Now, what about caching a page, like the OP asks? ^^

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.