View Full Version : Prevent caching of a page with PHP?

10-22-2004, 07:41 PM
Any way to do this? All HTML related ways I tried didn't work. :(

10-22-2004, 08:11 PM
Try a few of the things listed in this thread. Iknow it's aout Safari, but the headers are all the same :)

10-22-2004, 10:02 PM
Tried that code & IE kept on caching the page no problems. :mad:

10-22-2004, 10:41 PM
It should work with IE too.

10-26-2004, 10:56 AM
Tried that code & IE kept on caching the page no problems. :mad:
Did you happen to clear the original version of the page from IE's cache before you reloaded the no-cache version of the page?

Most no-cache methods simply stop the caching process; they don't instruct the browser to ignore or delete previously cached copies.

10-26-2004, 11:33 AM
you can't realy prevent it in a bulletproof way, sine it's a completely clientsided process.

i never understood why people bother with this. what are you trying to accomplish with it?

10-26-2004, 02:10 PM
Yes. I deleted all previously cached files from my cache but it keeps adding them back when I load the page again.

i never understood why people bother with this. what are you trying to accomplish with it?

Well, I use those random image type things on my register page & some other pages & I had the problem of if a user caused an error that when they would go back it would load the cached image.. I fixed this by setting a session variable that will update each time they load that page in their session & create the image based on that... for example:

$x = $_SESSION['number'];


This fixes that problem... but if their session expires or they go back to one of the pages that has this then they will see the cached images, hence, the images will display the incorrect code & they will get told what they put in was wrong (which was caused because it displayed the cached image & not the new file from the server).

10-26-2004, 03:32 PM
So they get the wrong immage ... which isn't realy a problem if you include in your errormessage that they should not use the backbutton. (actually, a good browser wount get the page from the cach, but will rebuild the previous state, so caching only works in 'bad' browsers)

The way i solve it is to 'clear' the pages. When the pae with the image on is requested, you set some flag in a sessionvariable or record the pagename or pageID in a table.
Then, when hey post the form with the securityimage-value, you check if this flag (or db-entry) is set, and then you immedeately clear it.
If it wasn't set, you know they didn't request the page with the securityimage from the server. So you can then immedeately redirect them to the page with a customised errormessage ('don't use the backbutton ... enter new number')

some more info:
http://www.codingforums.com/showthread.php?t=28073&highlight=back+cleared (link wount be active anymore, i think)

another usefull hack, is adding a value to the querystring of the page with the securityimage. like the timer() or so. That way, a browser will normally always request it from the server. (never tried it though)

10-29-2004, 12:10 PM
Thanks for the ideas Raf! :thumbsup:

10-29-2004, 01:00 PM
you're welcome :thumbsup: