Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

69 lines (44 sloc) 2.456 kB

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.

Installation

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:

[Doctor]
src   = img/drwho.jpg
alt   = Tom Baker
url   = http://www.bbc.co.uk/cult/doctorwho/
title = Dr. Who

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

[Kubrick]
src   = http://www.visual-memory.co.uk/images/photo.jpg
alt   = Stanley
url   = http://www.kubrick.com/
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:

[Doctor]
src   = img/drwho.jpg
alt   = Tom Baker
url   = http://www.bbc.co.uk/cult/doctorwho/
title = Dr. Who
id    = my_id
class = my_class

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

Jump to Line
Something went wrong with that request. Please try again.