close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

rotator.php doesn't work for me

Thread began 8/04/2009 5:32 pm by mick106153 | Last modified 8/06/2009 11:28 am by I-CRE8 | 4977 views | 5 replies |

mick106153

rotator.php doesn't work for me

Not a WebAssist question.
I'm trying to incorporate rotator.php so a different image is displayed in certain areas of the page each time it is reloaded. You can read about it here.
rotator.php
I'd like to use this one because it can size the images and carry a link so that I could display different products which could be clicked on for purchase.
The errors are:

Notice: Undefined index: id in /Users/mick/Sites/intuHorsesPowerStore/rotator.php on line 44

Notice: Undefined index: class in /Users/mick/Sites/intuHorsesPowerStore/rotator.php on line 48

If I comment those lines out it leads me down a path of subsequent errors. It should be obvious that php is not my strong suit and others seem to have no trouble with this code.
Please comment if you can.

Line 44 is - $id = $images[$img]['id'] ?

Line 48 is - $class = $images[$img]['class'] ?

Mick


Read me and php follow.

READ ME
"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 = doctorwho/
title = Dr. Who

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

[Kubrick]
src = photo.jpg
alt = Stanley
url = 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('plugins/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 = 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."

ROTATOR.PHP SCRIPT -

<?php

/*

Author: Dan Benjamin - hivelogic.com/

Copyright (c) 2004-2009 Hivelogic Corporation. All Rights Reserved.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE OR NONINFRINGEMENT.

IN NO EVENT SHALL DAN BENJAMIN, A LIST APART, OR AUTOMATIC, LTD. BE LIABLE
FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR
LOST PROFITS ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER
ARISING, INCLUDING NEGLIGENCE), EVEN IF DAN BENJAMIN OR HIVELOGIC CORP.
IS AWARE OF THE POSSIBILITY OF SUCH DAMAGES.

*/



# file containg your image descriptions

$IMG_CONFIG_FILE = 'images.ini';



# You shouldn't need to change anything below this point

function showImage( $ini=null ) {
global $IMG_CONFIG_FILE;
# if no custom ini file has been specified, use the default
$ini_file = $ini ? $ini : $IMG_CONFIG_FILE;
# read the config file into an array or die trying
$images = @parse_ini_file($ini_file,true);
if (! $images) {
die('Unable to read ini file.');
}
# pick a random image from the parsed config file
$img = array_rand($images);
# get the selected image's css id if one exists
$id = $images[$img]['id'] ?
sprintf( ' id="%s" ', $images[$img]['id'] ) :
'';
# get the selected image's css class if one exists
$class = $images[$img]['class'] ?
sprintf( ' class="%s" ', $images[$img]['class'] ) :
'';
# get selected image's dimensions
$size = @getimagesize( $images[$img]['src'] );
# if an url was specified, output the opening A HREF tag
if ( $images[$img]['url'] ) {
printf(
'<a href="%s" title="%s">',
$images[$img]['url'],
$images[$img]['title']
);
}
# output the IMG tag
printf(
'<img src="%s" alt="%s" %s %s%s/>',
$images[$img]['src'],
$images[$img]['alt'],
$size[3],
$id,
$class
);
# if an url was specified, output the closing A HREF tag
if ( $images[$img]['url'] ) {
echo('</a>');
}
}


?>

Sign in to reply to this post

I-CRE8Beta Tester

Mick,

your server is set to show warnings as well as errors and it is complaining that your ini file does not contain an id and class value.

The answer is to supply a blank value for each image like so:

[Doctor]
src = img/drwho.jpg
alt = Tom Baker
url = doctorwho/
title = Dr. Who
class =
id =

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

[Kubrick]
src = photo.jpg
alt = Stanley
url = www.kubrick.com/
title = Kubrick
class =
id =

Sign in to reply to this post

mick106153

Well Duh!!

That was pretty obvious.
I feel like a fool.
Never overlook the small stuff.

Thank you

Mick

Sign in to reply to this post

I-CRE8Beta Tester

No worries

Sign in to reply to this post

mick106153

Just made the change and it works like a charm.

Thanks again

Mick

PS.
Any way to time this script so that it could fire without a page reload?

Sign in to reply to this post

I-CRE8Beta Tester

No problem, glad it worked.

To fire the script you need to trigger a page reload, the only alternative would be to use a JavaScript Rotator

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...