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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[quote author=businessman332211@hotmail.com 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? ^^
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.