Generating random image in IE
I am currently finishing up the redesign of my site. On the left side of the text is a div that does nothing but display a background image using CSS and PHP. I want it so that everytime someone goes to a new page, this image changes. It works most of the time in Firefox, but it doesn't work in IE 8. I am assuming that the browser is just keeping the same style sheet or PHP file loaded from cache instead of refreshing it. So I want to know if there is a way for the site to force the refreshing with every page change.
Every page has
Code:
<div class="leftCol" id="random">
which is where the background image is displayed. id="random" refers to
Code:
#random {
background-image: url(../images/random/rotate.php);
background-repeat: no-repeat;
}
which is what places the image. And rotate.php is the following:
Code:
<?php
$folder = '.';
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
$img = null;
if (substr($folder,-1) != '/') {
$folder = $folder.'/';
}
if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
file_exists( $folder.$imageInfo['basename'] )
) {
$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
}
}
if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
}
}
?>
I am not sure if it's a browser thing, or if it's the CSS, or the PHP. But I would like it to be a new random image with each page. Is there a way to ensure this within the PHP file, and if so, how do I go about doing it? Or is it something else that needs to be done?