multiple random background images?
Moderator: General Moderators
multiple random background images?
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?
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.one after the other?
Both php and javascript could randomize the images.
Please clarify.
Not sure if this is what you need, but try something like this..
$images is the array the images are stored in. It will change randomly on reloads.
Code: Select all
<body background=<?=$images[shuffle($images)]?>>void shuffle ( array array) does not return a random index.
Something likeif the array has numerical indices without holes, oris more advisable
http://www.php.net/manual/en/function.array-rand.php
Something like
Code: Select all
...
srand(srand ((float)microtime()*1000000));
<body background="<?php echo $images[rand(0, count($images)-1)]; ?>">Code: Select all
srand(srand ((float)microtime()*1000000));
<body background="<?php echo $images[array_rand($images)]; ?>">http://www.php.net/manual/en/function.array-rand.php