PDA

View Full Version : randomizing images


AN-net
01-13-2005, 01:58 AM
it seems that my code will randomize if i run the the script through the browser but it doesnt randomize if i put it in an image page

<img src="$vboptions[bburl]/banners.php" />


and

the code is:

<?php
$img= array();
$img[] = "banner1.gif";
$img[] = "banner2.gif";
$img[] = "banner3.gif";
$img[] = "banner4.gif";
$img[] = "banner5.gif";
$img[] = "banner6.gif";
$img[] = "banner7.gif";
$img[] = "banner8.gif";
$img[] = "banner9.gif";
$dir = "http://dev.animationation.net/images/banners/";
$rand = rand(0, count($img) - 1);
$img = $img["$rand"];
header("Location: $dir$img");
?>

cinq
01-13-2005, 02:24 AM
header("Location: $dir.$img");

AN-net
01-13-2005, 02:48 AM
that didnt work...

cinq
01-13-2005, 03:01 AM
Why not do this :

in your code :

<?php
$img= array();
$img[] = "banner1.gif";
$img[] = "banner2.gif";
$img[] = "banner3.gif";
$img[] = "banner4.gif";
$img[] = "banner5.gif";
$img[] = "banner6.gif";
$img[] = "banner7.gif";
$img[] = "banner8.gif";
$img[] = "banner9.gif";
$dir = "http://dev.animationation.net/images/banners/";
$rand = rand(0, count($img) - 1);
$img = $img["$rand"];
$path = "<img src=\"".$dir.$img."\">";
?>

The above is the banner.php file.

Then use an include in your main page you want to show the banner in :

include('./banner.php');


and place :

echo $path;

whereever u want it to show.

rake
01-13-2005, 06:29 AM
That's the wrong way to do it. You need to read the file data, set some header information and then echo it out. Look at attachment.php for an example.

deathemperor
01-13-2005, 11:56 AM
if you had

<img src="$vboptions[bburl]/banners.php" />

then why would you need
$dir = "http://dev.animationation.net/images/banners/";
in the random script ? I mean the url for the images' location.

and if you use it in vb3 why don't we use a template ?

and (yes, and T_T) why not mt_rand ?

AN-net
01-13-2005, 08:26 PM
it outputs the image but it doesnt change the image unless i visit the script directly.

my current code is:

<?php
$img= array();
$img[] = "banner1.gif";
$img[] = "banner2.gif";
$img[] = "banner3.gif";
$img[] = "banner4.gif";
$img[] = "banner5.gif";
$img[] = "banner6.gif";
$img[] = "banner7.gif";
$img[] = "banner8.gif";
$img[] = "banner9.gif";
$img[] = "banner10.gif";
$dir = "http://dev.animationation.net/images/banners/";
$rand = mt_rand(0, count($img));
$randimg = $dir;
$randimg .= $img["$rand"];
header('Content-type: image/gif');
header('Location: '.$randimg.'');
?>