|
Posted by J.O. Aho on 05/26/05 16:05
(¯`·..Yttrium ...·´¯) wrote:
> With php, you can easily pick a random picture on your server, but you can't
> slide them each 10 seconds.
> To do this, you must have a look to a javascript function.
> Php is a server-side language, and you need a client -side one
Of course you can do that, no problems at all really.
--- thispage.php ---
<?PHP
/* Reload this page every 15th second */
header("Refresh: 15; URL=http://www.example.net/thispage.php");
/* Array of images that can be selected, the path is relative to the
php page in the same way as it is when you give a path in a HTML page */
$images=array(
"image/image1.jpg",
"image/image2.gif",
"image/image3.png",
"image/image_A.png"
);
?>
<html>
<head>
<title>Random image</title>
</head>
<body>
<img src='<?PHP echo $images[rand(0,(count($images)-1)]; ?>'>
</body>
</html>
--- eof ---
If you don't want to display the same image more than once, you have to use
cookies to track what images the user already seen and see to remove those
from the array before letting rand() to take care of the randomness.
//Aho
[Back to original message]
|