david.marks Posted July 19, 2006 Share Posted July 19, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/15081-how-do-i-prevent-back-from-rebuilding-dynamic-php-page/ Share on other sites More sharing options...
number9dream Posted July 19, 2006 Share Posted July 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15081-how-do-i-prevent-back-from-rebuilding-dynamic-php-page/#findComment-60673 Share on other sites More sharing options...
Ninjakreborn Posted July 19, 2006 Share Posted July 19, 2006 You can stop this easily with a number of ways with php, at the very top of the page put downVERY 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 Link to comment https://forums.phpfreaks.com/topic/15081-how-do-i-prevent-back-from-rebuilding-dynamic-php-page/#findComment-60676 Share on other sites More sharing options...
Joe Haley Posted July 19, 2006 Share Posted July 19, 2006 [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? ^^ Quote Link to comment https://forums.phpfreaks.com/topic/15081-how-do-i-prevent-back-from-rebuilding-dynamic-php-page/#findComment-60694 Share on other sites More sharing options...
david.marks Posted July 19, 2006 Author Share Posted July 19, 2006 Agreed that this is excellent information. (And thank you for the prompt reply.)However, I am looking to resolve the opposite problem. Pages that I would expect to be cached are NOT. (I have tested in both Firefox and IE) Quote Link to comment https://forums.phpfreaks.com/topic/15081-how-do-i-prevent-back-from-rebuilding-dynamic-php-page/#findComment-60696 Share on other sites More sharing options...
Ninjakreborn Posted July 20, 2006 Share Posted July 20, 2006 cookies, or sessions, to force them. Quote Link to comment https://forums.phpfreaks.com/topic/15081-how-do-i-prevent-back-from-rebuilding-dynamic-php-page/#findComment-60969 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.