• 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

Random Image Everytime You Refresh

soulm8sflyff

New Member
Well, this might just be a simple php script and everybody knows about it, but for the sake of those who don't, here it is.

Use your favorite text editor i.e. (Notepad) and copy this:

Code:
<?php

$random = "random.txt";

$fp = file($random);
srand((double)microtime()*1000000);
$rl = $fp[array_rand($fp)];
echo $rl;
?>

Now save that as random.php and drop it in a folder where in the desired images to be randomly shown everytime you refresh are stored.

Meanwhile, open your text editor again and make a path where in the php would find the images i.e. (your root folder/pics), so it would look like this:

Code:
<a href="buyme.php"><img src="/pics/banner1_advert.gif" border="0"></a>
<a href="buyme.php"><img src="/pics/banner2_advert" border="0"></a>

etc. etc. Note: the "<a href=. . . . " will be the link where in your browser would lead you when you click the image, this time, it's a banner advertisement. Now save that as random.txt and drop it again in the folder where the random.php and the images are stored. (the folder: "pics")

Our plan here is to make a random image so that everytime somebody visits your site, he will see a banner with your advertisement there. And when he click it, he will be lead to the page where he can sign up or buy your advertisement. The advantage of a random image is that people wont be bored by the same image always showing up everytime they visit your site. So if you want to advertise, make a lot of cool banners and make them as a rotating image that changes everytime you visit the page where in your banners are put.

Now to put the random image to the page. Choose the best place where to put your banner, i.e. at the top of the page, then just copy this code. It will be the same code for every random image for all the pages you wish to put in. Note: this code is based on the random.php and random.txt and the images which are put in the folder "pics" in your root folder. If you wish to put the images, the random.php and the random.txt in a different folder, you should change the path in this code as well as the path in the random.txt. Don't worry about the random.php, as long as you named the .txt file as random.txt, no need to worry.) So here's the code.

Code:
<?php include("http://yourwebsite/pics/random.php"); ?>

Be sure to change "yourwebsite" to the name of your website and be sure to have the correct path as well. Enjoy! Cheers! :D

Thanks to my good ol' friends MaGic for the script and Kwek for telling me how to do the link.
:wink2:
 
Back
Top