what is a browser detect? | how auticomplete jquery works | upgrade debian squeeze to jessie


Create a Simple Banner Rotator with PHP in a Minute

PHP shuffle randomizes (shuffles) the order of the elements in an array. You may use this function to create a simple banner rotator.

Define your banners

Create $banners array with the links of each banner. Then shuffle this array.

$banner1 = '<a href="BANNER1_URL" target="_blank"><img src="BANNER1_IMG_SRC" alt="BANNER1_ALT" title="BANNER1_TITLE"></a>';
$banner2 = '<a href="BANNER2_URL" target="_blank"><img src="BANNER2_IMG_SRC" alt="BANNER2_ALT" title="BANNER2_TITLE"></a>';
$banner3 = '<a href="BANNER3_URL" target="_blank"><img src="BANNER3_IMG_SRC" alt="BANNER3_ALT" title="BANNER3_TITLE"></a>';
$banner4 = '<a href="BANNER4_URL" target="_blank"><img src="BANNER4_IMG_SRC" alt="BANNER4_ALT" title="BANNER4_TITLE"></a>';
$banners = array($banner1, $banner2, $banner3, $banner4);

Display random banner

Just put this code, where you want to display your random banner

	<?php print $banners[0] ?>


The result of the above code is:


Refresh the page to see the banner rotation in action.


From PHP manual

Sign-up for our free email newsletter. Get updates when new tutorials and tips are published. You can unsubscribe anytime with a click.

Your comments are welcomed!

This site actively encourages commenting on any post. Comments are not pre-moderated, but this community does not tolerate direct or indirect attacks, name-calling or insults. Please, read terms of use and Comment Policy at privacy policy.

More tips