You are here: Re: random images « All PHP « IT news, forums, messages
Re: random images

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация