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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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