Jump to content

Chrome, Random Image


imdead

Recommended Posts

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="" />

Link to comment
https://forums.phpfreaks.com/topic/227105-chrome-random-image/
Share on other sites

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..

Link to comment
https://forums.phpfreaks.com/topic/227105-chrome-random-image/#findComment-1171628
Share on other sites

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.