How to display Random Banner from Folder with given URL with PHP?

Step 1: you have to put the following code where your want to display random images from the folder:

$bannerAd[1] = '<a href = \'http://www.yoursite.com\'><img src=http://www.yoursite.com/banner1.jpg alt=\'Banner1\' border=0></a>';
$bannerAd[2] = '<a href = \'http://www.yoursite.com\'><img src=http://www.yoursite.com/banner2.jpg alt=\'Banner2\' border=0></a>';
$bannerAd[3] = '<a href = \'http://www.yoursite.com\'><img src=http://www.yoursite.com/banner3.jpg alt=\'Banner3\' border=0></a>';
$adCount = count($bannerAd);
$randomAdNumber = mt_rand(1, $adCount);
echo $bannerAd[$randomAdNumber];

Step 2: Set Image path and URL.
Step 3: And Enjoy the Random Image selected from your folder.

Advertisements

Speak Your Mind

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: