The Random Image Rotator
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Hivelogic Image Rotator

This PHP script and accompanying .ini file will rotate an image from a pool of images every time a web page is visited (or reloaded).

Unlike JavaScript-based image rotators, this is a server-side script and the rotation happens when the page is loaded.


For the most basic installation, just drop the rotator.php file along with the images.ini into the same folder on your webserver.

You'll need to include the rotator.php file in your current page. The easiest way to do this is using the include directive near the top of your page:

<?php include('rotator.php'); ?>

Edit the images.ini file and create a few code blocks to point at your images, specifying the source, alt tag, url, and title tag for each image, like this:

src   = img/drwho.jpg
alt   = Tom Baker
url   =
title = Dr. Who

You can also specify images on remote servers if you want, like this:

src   =
alt   = Stanley
url   =
title = Kubrick

Then add the following image tag into your web page:

<?php showImage(); ?>

Reload the page, and you'll see the different images appear each time.

You don't have to determine an image's height or width yourself - the script will handle it for you, and generate the proper img tag on the fly once it has randomly selected the image.

Multiple Rotating Images

You can display different sets of rotating images by specifying different configuration files like this:

<?php showImage('myprecious.ini'); ?>

You can do this as many times as you'd like, on any page you'd like, or even multiple times within the same page.

Linkless Images

If you want to display images without linking them, just leave the url value of the image entry in the config file blank, or omit it entirely. If the rotator code doesn't find a URL, it will simply output the img tag without the surrounding a href tags.

Custom CSS ID's or Classes

Optionally, you can specify both an id or class tag in the configuration file, like this:

src   = img/drwho.jpg
alt   = Tom Baker
url   =
title = Dr. Who
id    = my_id
class = my_class

If the rotator script finds them, it will add them to the img tag. optional.