Jump to content

Image Rotator in IE7


Sharkbite

Recommended Posts

Hi,

I hope I am in the right forum. I am a graphic designer, not a programmer but more and more I am finding that I need to use some form of php in my websites. Right now I just wanted a simple image rotator that will rotate 4 images in a website randomly as you click through the site. The url is http://www.sharkbite.ca/sharktestsites/RyanVenier

the php code I used is

 <?php
$files = glob('{*.PNG,*.png,*.JPG,*.jpg,*.GIF,*.gif}', GLOB_BRACE);
readfile($files[array_rand($files)]);
?>

It works great in every browser EXCEPT IE7. The images do not rotate unless you refresh the page, I would like them to rotate as you click through (as they do in other bowsers). Can you help me with this?

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/
Share on other sites

I am not sure what you need,

The css is

.photo1 {
float: left;
height: 270px;
width: 212px;
}

the php (that I previously supplied, that's all there is)is here

http://www.sharkbite.ca/sharktestsites/RyanVenier/images/rotatingimages1/rotate.php

the html is

<div class="photo1"><img src="images/rotatingimages1/rotate.php"/></div>

Could this be to do with the way that IE re-uses images from the cache?  Instead of actually running the php script that is linked via <img src="...,  I am wondering if IE is simply saying "we have already seen that URL and I saved xxx.jpg into my cache for it therefore I will load that image again".

 

It may be worth testing some code that prevents the image from being cached.  I am not completely sure how these work; so in PHP you would need something like:

 

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header("cache-Control: no-store, no-cache, must-revalidate"); 
header("cache-Control: post-check=0, pre-check=0", false); 
header("Pragma: no-cache"); 

 

I am not sure if this would work best at the top of the page itself (which would mean changing the extension of all of your pages like 'services.html' to 'services.php' and encapsulating it around the standard PHP tags) or at the top of the rotate.php page.  Try it within the rotate.php page first.

 

Also, you can stop caching through HTML sticking the following within the <head> tags of your HTML pages.

 

<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="0">

 

See if that helps at all.

 

Just so you know, that is using an awful lot of unnecessary server resource. You can just pick the files from a directory and display the url to the file in each page. Something like:

 

<?php

// Taken from http://www.php.net/manual/en/function.readdir.php#90770
// This script is written by "HeadRoom" and not by myself.
// I made some modifications so that it only picks images.

$image_dir = 'images'; 
$image_types = array("PNG", "png", "JPG", "jpg", "GIF", "gif");
$count = 0; 
if($handle = opendir($image_dir)) { 
    $retval = array(); 
    while(false !== ($file = readdir($handle))) { 
        if(($file <> ".") && ($file <> "..") && in_array(end(explode(".", $file)), $image_types)) { 
            $retval[$count] = $file; 
            $count++; 
        } 
    } 
    closedir($handle); 
} 
shuffle($retval); 
$current_image = $retval[0];

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.