sessions and cache issue
To enable the use of the back button in combination with sessions, I added the following line to the top of my pages:
This works well, but now I have the problem that when someone clicks on a link they see the 'old' cached page which doesn't reflect the latest changes.
What I would like is the following:
-When people use the back button they should see the cached page
-When they click on a link they should see the "non-cached" page which reflects the latest changes.
How can I accomplish this?
You need to send a no-cache header, here is a sample of one.
This basically tells the browser to dump the page because its too old and make a new one from scratch.
header("Expires: Mon, 14 Jul 1996 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
I hope that helps.
If I don't cache the page then the back button won't work, so the nocache headers would not help here.
When I use sessions my pages are not cached by default.
That's why i used : ini_set("session.cache_limiter","public");
Now the pages are being cached and the back and forward button works, but I need the browser to show the 'newest' pages instead of the cached ones.
How can I enable the use of the back and forward buttons in combination with sessions and have the browser display the most recent changes when people click on a link?
I hope I'm clear enough :)
You can trick the browser into not caching the links when people click on them by tacking on a unix timestamp on the end of the link, this way the browser thinks its a new page and you will fool the cache into thinking that way too.
<a href="somelink.php?somevar=someval&ck=<?=time()?>">go there</a>
I use ck it stands for cache killer, but you can use whatever as long as it doesn't conflict with some other var you may be using. I hope that helps.
freddy is right, you could try that.
my version was only to have ti clean out the cache to fetch a page, but it does eat the users bandwith trying to reload every page.
I tried Freddy's suggestion and it works!
Freddy and Theiggsta, thank you for your help!