Forum Moderators: coopster
I am brand new to php and decided to jump in when I needed a random image rotator on my site. A PHP script which was posted on A List Apart seemed a perfect, simple solution. However, I'm having a slight problem, and since the discussion threads are closed on the article, I thought I would post here. The script was working fine until I started testing in IE 6.
Here is the php code {again, this was developed by automatic labs, and kindly made available for free on ALA}
-----------------------
<?
$folder = '.';
$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);
}
}
?>
Here is my problem (and it may be just the nature of the code, which I'm hoping someone can tell me):
In IE 6, when I refresh the page I"m on, the images rotate. However, when I click to other pages on the site, which also have the php code, the image stays the same.
While troubleshooting, I found that changing the IE temp internet files settings to "Check for newer versions of stored pages [every time I visit]" instead of [automatically] solved the problem. But, I'm guessing most users won't have the former setting.
I am not having this problem in FF or NN.
Any suggestions/guidance would be greatly appreciated.
thank you~
heather