Tech Support Guy banner
Status
Not open for further replies.
1 - 12 of 12 Posts

·
Registered
Joined
·
1,044 Posts
Discussion Starter · #1 ·
I want a radom image loaded on a webpage through folder, automatically on every refresh. Currently i am using a script http://www.alistapart.com/d/randomizer/rotate.txt

this script is working absolutely great, just i am looking a way to create a link for the image to go on some URL.

Can anyone tell me any other script which is in php?
 

·
Registered
Joined
·
82 Posts
You can try the script located at http://ma.tt/scripts/randomimage/. It is similar to the previous script you were using, however this one uses standard HTTP headers instead of reading the entire image file like the last script did, thus making it possible to link your image. For example:

Code:
<a href="http://some.url"><img src="rotate.php" alt="A Random Image"></a>
 

·
Registered
Joined
·
2,382 Posts
PHP:
<? // The microtime() function returns the current UNIX timestamp, in microseconds
srand((float) microtime() * 10000000);

//next, define images and links in the array
//you can use absolute or full url's, if you need more, add them in the same array as the existing links
//
$image[1]['pic']='banners/image1.jpg';
$image[1]['link']='link1.php#1';

$image[2]['pic']='banners/image2.jpg';
$image[2]['link']='link1.php#2';

$image[3]['pic']='banners/image3.jpg';
$image[3]['link']='link1.php#3';

$image[4]['pic']='banners/image4.jpg';
$image[4]['link']='link1.php#4';

$image[5]['pic']='banners/image5.jpg';
$image[5]['link']='link1.php#5';

//create the statement to show the images
$rn = array_rand($image);

//then display the image and link on the page
echo '<a href="'.$image[$rn]['link'].'">';
echo '[IMG]'.$image[$rn]['pic'].'[/IMG]';

?>
That should get you what you wanted. Here is a test link on my site to try it out.
 

·
Registered
Joined
·
1,044 Posts
Discussion Starter · #5 ·
Thanks for the code, is this possible in your code to set - only random image on refresh and not automatically load the another image or some fade in transition between them because currently not looking good. Secondly, link blue border also removed from the image.

Can't possible some editing in this script : http://www.alistapart.com/d/randomizer/rotate.txt
 

·
Registered
Joined
·
2,382 Posts
Hey, that is exactly what the script does, other than a fade in. If you want fading, you need to use flash or DHTML (with JS)
http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm

The sample page reloads to show you the sample of the randomness of the images loaded, it is not part of the script or intended to be shown.

You can easily remove the blue border by adding border="0" to the code to display the images.
Code:
//then display the image and link on the page
echo '<a href="'.$image[$rn]['link'].'">';
echo '<img src="'.$image[$rn]['pic'].'" border=\"0\">';
Maybe someone can modify your code.
 

·
Registered
Joined
·
2,382 Posts
Actually, it is your table that is doing that, not my script. Remove the &nbsp: from the empty tables and the

Make the table background the same as the page background and that will disappear.

bgcolor="#333333"

You can view your exact page here
 

·
Registered
Joined
·
2,382 Posts
1 - 12 of 12 Posts
Status
Not open for further replies.
Top