Hi all

Have just updated my website to include a bit of scripting that allows every page to generate four random images at the top right as you can see here:

http://rebootclub.com

It works perfectly in Firefox and Internet Explorer. Every time you go to a new page, the images change. Not on Google Chrome though - the images stay the same on every single page. Can anyone advise how to fix this?

Cheers

    If you mean the images at the top next to the logo, then they change just fine for me on both Chrome and Fx. I notice that you're using a PHP script to randomly serve up the images. Try adding a unique timestamp to each image URL:

    scripts/rotate1.php?t=1234567890

    You could make the timestamp a mixture of the image number (1-4) and the current timestamp, ensuring that browsers will always think it's a different image file, even if it's all using the same script.

      Hi Ashley

      Thanks for the prompt response. Would I have to make all the pages on the site .PHP ones instead of .HTML if I'm going to be inserting a bit of timestamp-code?

      (I'm a real newbie so, forgive me if this is a really stupid question... 🙂 )

      cheers

      Darren

        The timestamp would need to be added from somewhere, whether it be at the server in PHP or on the client-side with Javascript. Although you can't rely on it Javascript being available, it's not a huge issue if the same images are shown again to clients that have it disabled/stripped out, so it might be better to added it in there.

          Ashley Sheridan;10983762 wrote:

          Try adding a unique timestamp to each image URL:

          scripts/rotate1.php?t=1234567890

          You could make the timestamp a mixture of the image number (1-4) and the current timestamp, ensuring that browsers will always think it's a different image file, even if it's all using the same script.

          This, IMHO, is a cheap workaround rather than a fix (just like using ob_start() to avoid the 'headers already sent' error).

          If you want to tell the browser that it's a new image that shouldn't be cached, then do just that; use [man]header/man to send out the appropriate Cache-Control, Expires, etc. header(s) rather than attempting to trick the browser into this behavior by attempting to modify the URL each time.

            I'm trying to stick to server-side scripting with all the stuff I'm learning so I'm guessing it's time to rename all the pages to have a .PHP suffix...?

              There are browsers (IE) that have a habit of ignoring headers, which is one of the main reasons this hack exists. I know it's not pretty, but it is a simple solution to the problem. If you know that your visitors aren't using older versions of IE, or you don't care (personally I would put myself in the latter, but as I can't speak for everyone I offer a solution for anyone who might) then you can rely on the headers. You are right though when you say it's a cheap workaround, but when some people are still using crappy browsers, we're left in a mess :-/

                ok, i've tried inserting this at the very top of the home page on the site

                <?php
                	header("Cache-Control: no-cache, must-revalidate");
                ?>

                ..and it doesn't make one scrap of difference. When returning to the home page, those 4 images at the top right still remain the same (in Google Chrome).

                Stumped 🙁

                  Have you tried forcing Chrome to refresh its cache? It could be that because it cached the images once already, it won't see the new headers as any date value returned by the server will also be the same. Forcing a refresh will mean that Chrome will pick up the new headers, and from then on it will know to never cache.

                  As it stands, it's already cached, so setting a new header won't help because Chrome doesn't go as far as grabbing a new image and seeing the new header (at least, that's how I see it)

                    ok, I tried clearing the cache but it still made no difference. To be honest, I'm thinking of just gong with the quick fix method first offered up above as, thinking about it, I don't want all the images on every page to be refreshed every time as some pages have a lot of images that could start to suck up a lot of bandwidth...

                      How did you force your Chrome to refresh its cache? Are you sure it really did? What happens if you visit the same URL as the image tags are using and force refresh those?

                        Dustie;10983826 wrote:

                        ok, i've tried inserting this at the very top of the home page on the site

                        <?php
                        	header("Cache-Control: no-cache, must-revalidate");
                        ?>

                        There's your problem.

                        I was suggesting adding that header to the images themselves. It's not the home page that appears to be getting cached, is it? If not, then that header won't affect the images at all, since your browser is making a separate request to load them.

                        You need to add that header to the HTTP response for the images themselves.

                          Write a Reply...