Sharkbite Posted June 9, 2010 Share Posted June 9, 2010 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 More sharing options...
kenrbnsn Posted June 9, 2010 Share Posted June 9, 2010 We need to see more code. Ken Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070091 Share on other sites More sharing options...
Sharkbite Posted June 9, 2010 Author Share Posted June 9, 2010 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> Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070095 Share on other sites More sharing options...
jd307 Posted June 10, 2010 Share Posted June 10, 2010 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. Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070170 Share on other sites More sharing options...
Sharkbite Posted June 10, 2010 Author Share Posted June 10, 2010 Yes, the code on the rotator.php did work. Thanks! The HTML meta tags did not by the way. Cheers. Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070423 Share on other sites More sharing options...
mattal999 Posted June 10, 2010 Share Posted June 10, 2010 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]; ?> Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070426 Share on other sites More sharing options...
Sharkbite Posted June 10, 2010 Author Share Posted June 10, 2010 Awesome, I will give it a try, thanks. Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070430 Share on other sites More sharing options...
kenrbnsn Posted June 10, 2010 Share Posted June 10, 2010 To make this even shorter, use the glob function: <?php $retval = glob('images/*.{PNG,png,GIF,gif,JPG,jpg}',GLOB_BRACE); shuffle($retval); $current_image = $retval[0]; ?> Ken Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070434 Share on other sites More sharing options...
Sharkbite Posted June 10, 2010 Author Share Posted June 10, 2010 Thanks but I couldn't get those last two to work, the images would not appear, I had to go back to the first one. Link to comment https://forums.phpfreaks.com/topic/204324-image-rotator-in-ie7/#findComment-1070447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.