Forum Moderators: coopster

Message Too Old, No Replies

Problem with FireFox caching images

Images placed via css and php

         

abbeyvet

2:30 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using a PHP script to place a random background image on a div using CSS. The div is a header type thing and appears on all pages.

So:

background-image: url('/images/random/random.php');

It works as it should in IE, that is to say that as you browse a different image appears on each page.

In FireFox an image is generated but it does not change as the site is browsed. However, if you right click and choose 'View background image', random images appear rather than the one which is displayed.

Refreshing the page does refresh the image.

I do NOT want to prevent caching of the pages, so cannot use header on the pages to prevent caching. I just want not to cache the script serving the images, or rather to make it somehow always serve a new image.

Is that possible?

I have already tried putting stuff like:

header(”Cache-Control: no-cache, must-revalidate”);
header(”Expires: Mon, 26 Jul 1997 05:00:00 GMT”);

into the script itself, but it does not have any effect, which I expected as it is not in the header of the pages themselves.

Any suggestions?

StupidScript

6:33 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about if you perform the image randomization before including it in the CSS? Something like:

<?$randimg="/images/random/random.php";?>

background-image: url('<?=$randimg?>');

Since FF doesn't like to re-get stuff embedded in CSS, perhaps this will force a new get per page ...?