Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 david.marks

david.marks
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 July 2006 - 09:18 PM

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?

#2 number9dream

number9dream
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 19 July 2006 - 09:59 PM

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.

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 July 2006 - 10:06 PM

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.
<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>
that'll do it in asp just as a note.
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
That will do it for the most part in the form of html, but it's not guaranteed.
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");
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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Joe Haley

Joe Haley
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts
  • LocationCanada, eh?

Posted 19 July 2006 - 10:55 PM

<?php
header("Cache-Control: no-cache, must-revalidate");
?>
With this you never have to worry about caching of that page again.


Why isn't the page being cached and simply reloaded?


Verry nice and informative. Now, what about caching a page, like the OP asks? ^^
Give a man a fish; you have fed him for today.  Teach a man to fish; and you have fed him for a lifetime
Don't teach men to program. Teach them to fish.

Please, try the RTFM solution before asking for help:
http://php.net/manual/en/index.php

#5 david.marks

david.marks
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 19 July 2006 - 11:00 PM

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)

#6 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 20 July 2006 - 12:51 PM

cookies, or sessions, to force them.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users