Hi!

 I'm using an image rotator PHP script that randomly rotates 1 png image and 5 gifs.  Firefox and Gecko engine browsers cache the first image that it loads and keeps it that way, even when refreshed (when its supposed to display a new image).  IE does not have this problem.  Does anyone have like a no-cache or an always-revalidate script?  Obviously, the src looks like this <img src="rotate.php" alt="blah blah">.

Thanx! 😃 😃

    I use the following script at the top of a header file that is the very first thing included in every page. Pay attention to the comments: the headers must be the very first thing in the html output stream, nothing, not even 1 whitespace can prcede them or they will not work

    <?php		//header.php
    //disable all browser caching MUST BE FIRST LINES WITH NO PRECEEDING SPACES ETC
    // Date in the past
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    
    // always modified
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    
    // HTTP/1.1
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    
    // HTTP/1.0
    header("Pragma: no-cache");
    
    ?>
    

      Another really cheap trick is to simply throw a random number into every one of your links. This forces your browser into thinking you have a fresh URL each time.

      I wrote something awhile back...
      seemed to have issues with a client's cruddy browser or id10t issues 😉

      It was somthing like this:

      
      function nocachelink($url) {
      	$delimiter = ( strstr($url, '?') ) ? "&" : "?";
      	return $url . $delimiter . "nocache=" . uniqid(rand(), true);
      }
      
      

      Anyway, I didn't have to worry about some stupid browser or proxy server ignoring headers (they seemed to in the issue I was having with the client.)

        Write a Reply...