Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Prevent caching of a page with PHP?

    Any way to do this? All HTML related ways I tried didn't work.

  • #2
    Regular Coder trib4lmaniac's Avatar
    Join Date
    Feb 2004
    Location
    Cornwall, UK
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try a few of the things listed in this thread. Iknow it's aout Safari, but the headers are all the same

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Tried that code & IE kept on caching the page no problems.

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    It should work with IE too.

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    256
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cyphix
    Tried that code & IE kept on caching the page no problems.
    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.

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    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'];

    image$x.jpg

    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).

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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/showthre...t=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)
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #9
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks for the ideas Raf!

  • #10
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you're welcome
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •