Web Analytics Made Easy -
StatCounter prevent loading of cached image - CodingForum

Announcement

Collapse
No announcement yet.

prevent loading of cached image

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • prevent loading of cached image

    Is there some way that I can not load one image from the cache? It is replaced all of the time, and needs to not load from the cache.
    designsbychris.com

  • #2
    I dont know if this will apply to images aswell but you could try:

    <meta http-equiv="pragma" content="no-cache" />
    PHP Weekly - A PHP Developers Resource
    PHP 5.1.4 and Ruby on Rails web hosting
    Moderator of PHP and Work offers and Requests
    Install Apache/PHP/MySQL
    (by marek_mar) | TinyPlugin Architecture

    Comment


    • #3
      Doesn't that code prevent things from going into the cache? I want pages and images to be cached. On a certain page, I want the image that is loaded to not load from the cache. Does that make sense?

      It's not that I want an image to be prevented from being cached, I just don't want it to be loaded from that cache when it is referenced in a particular page.
      designsbychris.com

      Comment


      • #4
        Do you have any form of server-side access. Im not sure about ways to specificly say what can be loaded from the cache and what not, but If you could access PHP you could use something like:

        Code:
        <a href="image.php" alt="Blah" />
        then have:

        PHP Code:
        header("Content-Type: image/jpeg");
        readfile("image.jpg"); 
        which should in theory reload the image every time
        PHP Weekly - A PHP Developers Resource
        PHP 5.1.4 and Ruby on Rails web hosting
        Moderator of PHP and Work offers and Requests
        Install Apache/PHP/MySQL
        (by marek_mar) | TinyPlugin Architecture

        Comment


        • #5
          If your page is coming from a server side script (PHP or otherwise) you can use this simple technique:

          <img src="myimage.png?insert datetime stamp here" alt="Some text" />

          Use whatever function in your server side script that'll put the current date and time into that space after the ?.


          Please note that missing-score meant use: <img src="image.php" alt="Blah" /> and accidently wrote an <a> tag instead.
          Check out the Forum Search. It's the short path to getting great results from this forum.

          Comment


          • #6
            yeh sorry about that
            PHP Weekly - A PHP Developers Resource
            PHP 5.1.4 and Ruby on Rails web hosting
            Moderator of PHP and Work offers and Requests
            Install Apache/PHP/MySQL
            (by marek_mar) | TinyPlugin Architecture

            Comment


            • #7
              Yes, I am using php...so that will hopefully work! Thank you very much!
              designsbychris.com

              Comment


              • #8
                Here is a javascript solution which is much like Roy's suggestion in that it adds the UTC Time to a querry at the end of the image URL. If you check your TIP files you will find a different image cached eac time the page is called.
                Code:
                <script type="text/javascript">
                <!--//
                 var myImage = new Image()	
                 myImage.src = 'http://www.stadiumsofnfl.com/afc/aldelph102.jpg?';
                  function chkCache() {
                    var clocktime = new Date();
                    var utchours = clocktime.getUTCHours();
                    var utcminutes = clocktime.getUTCMinutes();
                    var utcseconds = clocktime.getUTCSeconds();
                    var utcyear = clocktime.getUTCFullYear();
                    var utcmonth = clocktime.getUTCMonth()+1;
                    var utcday = clocktime.getUTCDate();
                    var utctime = utcyear + utcmonth + utcday;
                        utctime += utchours + utcminutes + utcseconds;
                 
                      isNew = myImage.src;
                        if(!isNew.match('#')) {
                           document.images['noCache'].src = myImage.src+utctime;
                        }
                      else{document.images['noCache'].src = document.images['noCache'].src;
                    }
                  }
                 //-->
                </script>
                </HEAD>
                
                <BODY onload="chkCache()">
                <img name="noCache" src="http://www.stadiumsofnfl.com/afc/aldelph102.jpg" width="640" height="480" alt="Adelphia Coliseum">
                </CENTER>
                </BODY>
                </HTML>
                .....Willy

                Comment


                • #9
                  The php solution may be a better idea as people may have javascript disabled although both should work fine.
                  PHP Weekly - A PHP Developers Resource
                  PHP 5.1.4 and Ruby on Rails web hosting
                  Moderator of PHP and Work offers and Requests
                  Install Apache/PHP/MySQL
                  (by marek_mar) | TinyPlugin Architecture

                  Comment


                  • #10
                    If you go with the PHP solution, make your image script as specified. If you decide to write a "generic" script which can be used to pick off any image using a parameter passed on the URL (<img src="image.php?actualimagename.jpg" alt="Hah" />) you must also add code to the PHP script to validate the image name returned, otherwise you've opened a hole for hacking into your site and the hackers may do something like this: <img src="image.php?image.php" alt="Gotcha" /> and be able to read your scripts merely by looking in their cache.
                    Check out the Forum Search. It's the short path to getting great results from this forum.

                    Comment


                    • #11
                      I went with your original post, Roy, and it works great. Thanks.
                      designsbychris.com

                      Comment

                      Working...
                      X