imdead Posted February 9, 2011 Share Posted February 9, 2011 Hey guys, i've made a script to display a random image. Works perfect on firefox, ie but not chrome =/. Rotate.php <?php // rotate images randomly but w/o dups on same page - format: // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1' // for second, etc // (c) 2004 David Pankhurst - use freely, but please leave in my credit $images=array( // list of files to rotate - add as needed "images/1.jpg", "images/2.jpg", "images/3.jpg", "images/4.jpg", "images/5.jpg", "images/6.jpg", "images/7.jpg", "images/8.jpg", "images/9.jpg" ); $total=count($images); $secondsFixed=2; // seconds to keep list the same $seedValue=(int)(time()/$secondsFixed); srand($seedValue); for ($i=0;$i<$total;++$i) // shuffle list 'randomly' { $r=rand(0,$total-1); $temp =$images[$i]; $images[$i]=$images[$r]; $images[$r]=$temp; } $index=(int)($_GET['i']); // image index passed in $i=$index%$total; // make sure index always in bounds $file=$images[$i]; header ("Location: $file"); header ("Content-Length: 0"); exit; ?> and then to call it, script.php <img src='rotate.php?i=0' width="90%" height="90%" alt="" /> Quote Link to comment https://forums.phpfreaks.com/topic/227105-chrome-random-image/ Share on other sites More sharing options...
AtomicRax Posted February 9, 2011 Share Posted February 9, 2011 Try this: <?php // rotate images randomly but w/o dups on same page - format: // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1' // for second, etc // (c) 2004 David Pankhurst - use freely, but please leave in my credit $images=array( // list of files to rotate - add as needed "images/1.jpg", "images/2.jpg", "images/3.jpg", "images/4.jpg", "images/5.jpg", "images/6.jpg", "images/7.jpg", "images/8.jpg", "images/9.jpg" ); $total=count($images); $secondsFixed=2; // seconds to keep list the same $seedValue=(int)(time()/$secondsFixed); srand($seedValue); for ($i=0;$i<$total;++$i) // shuffle list 'randomly' { $r=rand(0,$total-1); $temp =$images[$i]; $images[$i]=$images[$r]; $images[$r]=$temp; } $index=(int)($_GET['i']); // image index passed in $i=$index%$total; // make sure index always in bounds $file=$images[$i]; header("Cache-Control: no-cache, must-revalidate"); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header ("Location: $file"); header ("Content-Length: 0"); exit; ?> Also header("Pragma: no-cache") is another no cache header.. Quote Link to comment https://forums.phpfreaks.com/topic/227105-chrome-random-image/#findComment-1171628 Share on other sites More sharing options...
imdead Posted February 9, 2011 Author Share Posted February 9, 2011 Nope, still only working on firefox and ie =/ Quote Link to comment https://forums.phpfreaks.com/topic/227105-chrome-random-image/#findComment-1171975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.