PDA

View Full Version : Simple PHP Rotating Script?



Ashed
April 15th, 2002, 15:38
Can anyone point me to simple PHP image rotating script? :)
I don't need to use a banner rotating script, just something simple should do.
It's mainly for my signature and avatar, I want different ones to show up everytime... :D

Seldimis
April 15th, 2002, 16:07
Do you mean that you want to rotate the avatars and signatures in this forum? I think you simply can't .

Else if you need a banner rotator try PhpAdsNew

Ashed
April 16th, 2002, 08:12
Nope, not on this forum.
It works on another forum...

skeptical
April 16th, 2002, 09:16
<?
$banners = array('banner1.jpg', 'banner2.jpg', 'banner3.jpg');
$rand = rand(0, count($banners)-1);

echo "<img src ="/http://www.blah.com/".$banners['$rand']."/>";

?>


I wrote that code as im a little sleepy. so i don't know if it work. test it.

Ashed
April 16th, 2002, 12:51
OK, thanks for that. I had to tweak something to make to make it work. :p



<?
$banners = array('blah.gif', 'bleh.gif');
$rand = rand(0, count($banners)-1);
echo "<img src =\"http://www.blah.com/".$banners[$rand]."\">";
?>

Ashed
April 16th, 2002, 12:59
It doesn't seem to work when put on webpages... :eek:

Testing...

http://clan.nuclearbox.com/stuff/avatar.php

OK, this works. But when I use <img src="http://clan.nuclearbox.com/stuff/avatar.php"> on an HTML page it doesn't seem to work. :(

Hmmm... Would this worK?



<?
$banners = array('blah.gif', 'bleh.gif');
$rand = rand(0, count($banners)-1);
header("Location: http://www.blah.com/".$banners[$rand]."");
?>

Ashed
April 16th, 2002, 15:26
Damn, it works but only sometimes.
I tried it on one of the forums that allows me to link my avatar from another server and sometimes it'd just give me a red X.
Can anyone tell me why this is happening?

agent007
April 16th, 2002, 17:34
You could create a dynamic image using PHP. Then just add a line in your .htaccess files and link to it.

Ashed
April 17th, 2002, 08:26
Hmmm...? :eek:

Anyway, I got this code to work flawlessly (I think). :D



<?
$banners = array('blah.gif', 'bleh.gif');
$rand = rand(0, count($banners)-1);
include("http://www.blah.com/".$banners[$rand]."");
?>

ducktape
April 17th, 2002, 21:27
checkout http://conceptsofreality.com and look at ride of the moment and then refresh is that what you are looking for. what is it does is call the images from the directory i choose and displays them and each time the page is loaded it displays a different image from that directory

skeptical
April 18th, 2002, 00:43
Try this:




<?
$banners = array('crap1.gif', 'crap2.gif, crap3.gif');
$rand = rand(0, count($banners)-1);
echo "<img src=http://www.blah.com/$banners[$rand]>";
?>


It works. Just change the image name in the $banners array and the url of your image.

Ashed
April 18th, 2002, 01:29
Originally posted by triad web host
checkout http://conceptsofreality.com and look at ride of the moment and then refresh is that what you are looking for. what is it does is call the images from the directory i choose and displays them and each time the page is loaded it displays a different image from that directory

Looks nice! :)
Is there anyway that I can see the code for it? :p

ducktape
April 18th, 2002, 02:31
save the below as rid.php and place in the directory u wanna call the pics from


<?php


//read folder
$folder=opendir(".");
while ($file = readdir($folder))
$names[count($names)] = $file;
closedir($folder);
//sort file names in array
sort($names);
//remove any non-images from array
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
//random
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
//random image from array
$slika=$names1[$rand_keys[0]];
//image dimensions
$dimensions = GetImageSize($slika);
if (isset($pic)){header ("Location: $slika");}
else {echo "<img src=\"$slika\" $dimensions[3]>";}
?>


place the below in the page u want to display the images on of course you can change the size and the alt trext and will need to change the url to the directory where u place the rid.php file above


<img src="images/rid.php?pic=random" height="125" width="175" alt="This image will change each time you refresh your browser or each time you revisit the main index page

Ashed
April 19th, 2002, 05:03
Thanks, michael. :p
I'll test the script out. :)

ducktape
April 19th, 2002, 10:28
no problem if you need help just ask it works quite well i think