Page 1 of 1
multiple random background images?
Posted: Wed Feb 26, 2003 1:48 am
by kananook
is their a way with php, without using php images, where you can have 10-20 background images? one after the other? then is their a way to add a simple php script to make these images random?
Posted: Wed Feb 26, 2003 7:58 am
by volka
one after the other?
If there is a new request: yes. If you want it to cycle after a certain amount of time: no. But you might use a client-side script (like javascript) to do so or let the browser
refresh the document after
x seconds.
Both php and javascript could randomize the images.
Please clarify.
Posted: Wed Feb 26, 2003 4:30 pm
by decoy1
Not sure if this is what you need, but try something like this..
Code: Select all
<body background=<?=$images[shuffle($images)]?>>
$images is the array the images are stored in. It will change randomly on reloads.
Posted: Wed Feb 26, 2003 4:45 pm
by volka
void shuffle ( array array) does not return a random index.
Something like
Code: Select all
...
srand(srand ((float)microtime()*1000000));
<body background="<?php echo $images[rand(0, count($images)-1)]; ?>">
if the array has numerical indices without holes, or
Code: Select all
srand(srand ((float)microtime()*1000000));
<body background="<?php echo $images[array_rand($images)]; ?>">
is more advisable
http://www.php.net/manual/en/function.array-rand.php