• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Simple PHP Rotating Script?

Ashed

New Member
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
 
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
 
PHP:
<?
$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.
 
Last edited:
OK, thanks for that. I had to tweak something to make to make it work. :p

PHP:
<?
$banners = array('blah.gif', 'bleh.gif');
$rand = rand(0, count($banners)-1);
echo "<img src =\"http://www.blah.com/".$banners[$rand]."\">";
?>
 
It doesn't seem to work when put on webpages... :eek:

Testing...

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?

PHP:
<?
$banners = array('blah.gif', 'bleh.gif');
$rand = rand(0, count($banners)-1);
header("Location: http://www.blah.com/".$banners[$rand]."");
?>
 
Last edited:
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?
 
Hmmm...? :eek:

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

PHP:
<?
$banners = array('blah.gif', 'bleh.gif');
$rand = rand(0, count($banners)-1);
include("http://www.blah.com/".$banners[$rand]."");
?>
 
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
 
Try this:


PHP:
<?
$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.
 
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
 
save the below as rid.php and place in the directory u wanna call the pics from
PHP:
<?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
 
Back
Top