HELP nocache but still allow back button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mike608
Forum Newbie
Posts: 2
Joined: Fri May 03, 2002 5:50 pm

HELP nocache but still allow back button

Post by mike608 »

Having trouble with this -- can't seem to find a difinitive answer.

I have a page that displays a new image from a post. But when I return to this page by clicking the back button, the page has expired.

Does anyone know how to disable cache BUT STILL still allow the user to click the back button (in the browser) and have a dynamic page displayed (ie data is drawn from the database).

Two problems: 1) If I disable the cache I can obtain the non-cached page by clicking a link that returns to this page. 2)If I enable cache, I get a cached page but I can click the back button. Catch 22 situation. Any way around this???

*note:
- I have tried header, session_cache_limiter, etc, etc.
-I do NOT want to use get instead of post

Thanks so much.

Mike.
pozytron
Forum Newbie
Posts: 12
Joined: Fri May 03, 2002 7:14 pm
Location: Denver

Post by pozytron »

There's not many ways to do this, because http is a stateless protocol. Don't bother messing around with headers, because it won't work that way. I can think of a few things:

* You can use cookies, and store the variables in cookies. This is not the preferred method because many people think that cookies are evil and turn them off.

* Really, GET would be the easiest way. I know you specifically stated you don't want to use it, but I don't see why. Is it because you don't want a super-long URL?

* The final, and most complicated method would be to set up a database that automatically registers a userid (stored in the url, i.e. page.php?uid=6 or with cookies). The database would need some sort of timeout feature where it automatically deletes inactive users. You'd then store your variables in the database. If you really don't want anything in the URL, you could be even more complicated and get the user's IP, store that, and associate some variables with it.

Other than the above obvious and cheesy ideas, you have me baffled.
Last edited by pozytron on Fri May 03, 2002 9:14 pm, edited 1 time in total.
mike608
Forum Newbie
Posts: 2
Joined: Fri May 03, 2002 5:50 pm

even GET method would not work perfectly right?

Post by mike608 »

Even if I use a get method, when I hit the back button in the browser, I will get stale data, correct?

Thank you very much for your time.

Mike.
pozytron
Forum Newbie
Posts: 12
Joined: Fri May 03, 2002 7:14 pm
Location: Denver

Post by pozytron »

It depends on whether the user has their browser set to cache pages or not, as you said. If their browser does not cache pages, it will refresh with dynamic content when you use GET. If their browser always uses pages from a cache, there's nothing you can do (that I know of).

Cheers,
Robin Hamilton-Pennell
ericling
Forum Newbie
Posts: 1
Joined: Mon Oct 14, 2002 10:09 am

Post by ericling »

So what is the final verdict? I am having the same problem... What solution have you come up with?
GroovyinAz
Forum Newbie
Posts: 8
Joined: Tue Oct 01, 2002 6:26 pm
Location: Tucson,AZ

I've tested this for u

Post by GroovyinAz »

Code: Select all

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
                                                     // always modified
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
I loaded a page that contains dynamic elements
I navigated forward
changed the database
and clicked back

The page displayed the new data without a refresh

Does this answer you question?
Post Reply