random image script not randomizing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

random image script not randomizing

Post by bruceg »

Hey guys (and girls)...

I am trying to implement a php image rotating script that is detailed here at a list apart
 
http://www.alistapart.com/articles/betterrotator
 
I can't get it to work though... (no rotating). The page I have added the script to is here:
 
http://www.inspired-evolution.com/
 
I *believe* I am doing every thing correctly, so I am puzzled as to why no rotation.
 
the php code I am using is:
 

Code: Select all

<?php

  $IMG_CONFIG_FILE = 'images.ini';

  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>');
    }
  }
?>
with the images listed in the images.ini file. and I am calling it on my page as such:

<?php require ('rotate.php'); ?><?php showImage () ;?>

 

the images in the images.ini file are listed exactly as shown in the ALA article
eg:

[ReachyourPeak]
src = images/logo_header3.jpg
alt = Inspired-Evolution.com - Reach your Peak!
title = Inspired-Evolution.com - Reach your Peak!

[LookintotheFuture]
src = images/logo_header1.jpg
alt = Inspired-Evolution.com - Look into the Future
title = Inspired-Evolution.com - Look into the Future

[SoartonNewHeights]
src = images/logo_header2.jpg
alt = Inspired-Evolution.com - Soar to New Heights
title = Inspired-Evolution.com - Soar to New Heights

and the ini and rotate.php file are at the same level as my index.php page as the article indicates to do with the images in a directory called 'images'.

 

any possible solutions that I might be missing to cause this not to work?

 

TIA
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

In the INI file " the values they contain non-alphanumerics.

Code: Select all

[ReachyourPeak]
src = "images/logo_header3.jpg"
alt = "Inspired-Evolution.com - Reach your Peak!"
title = "Inspired-Evolution.com - Reach your Peak!"

[LookintotheFuture]
src = "images/logo_header1.jpg"
alt = "Inspired-Evolution.com - Look into the Future"
title = "Inspired-Evolution.com - Look into the Future"

[SoartonNewHeights]
src = "images/logo_header2.jpg"
alt = "Inspired-Evolution.com - Soar to New Heights"
title = "Inspired-Evolution.com - Soar to New Heights"
bruceg
Forum Contributor
Posts: 174
Joined: Wed Mar 16, 2005 11:07 am
Location: Morrisville, NC
Contact:

Post by bruceg »

great, thanks!
Post Reply