ALA - A better image rotator

He has: 578 posts

Joined: Jun 2004

http://www.alistapart.com/articles/betterrotator/

I'm trying to get a random header going on my latest project, http://madclassifieds.000k.net/zap/ (html version)

The php version (which won't display) is at http://madclassifieds.000k.net/zap/index.php

When you go there (as you can see) it says cannot read ini file

the ini is at http://madclassifieds.000k.net/zap/imgs/headers/headers.ini

and the rotator script is at http://madclassifieds.000k.net/zap/imgs/headers/rotate.php

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

It would be nice to see the PHP code, not just a link to the file. Smiling If you're on Apache you might try saving copies of your .php files with the extension .phps. You can link to these files, and they'll display with syntax highlighting and all.

I'm guessing you have a path or permission problem. Let's see the code and file vitals. Smiling

He has: 578 posts

Joined: Jun 2004

whoops... my bad!

<?php
/*

  Author: Dan Benjamin - <a href=\"http://hivelogic.com/\" class=\"bb-url\">http://hivelogic.com/</a>

  Copyright (c) 2004 Automatic, Ltd. 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, A LIST APART, OR
  AUTOMATIC, LTD. IS AWARE OF THE POSSIBILITY OF SUCH DAMAGES.

*/



  # file containg your image descriptions

 
$IMG_CONFIG_FILE = 'http://madclassifieds.000k.net/zap/imgs/headers/headers.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>');
    }
  }
?>

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Try using an internal path to the file rather than a http url.

He has: 578 posts

Joined: Jun 2004

Still nothing

He has: 93 posts

Joined: Jun 2004

This is a very simple method I use for displaying random images

<?php

function randImage() {
    \\
3 is the number of images I have starting at 0
    $number
= rand(0,3);
    \\
path to images
   
echo "<img src=\"images/image" . $number . ".png\">";
}

?>
'
Just call the function from where you want the image to display, remember they must all be named correctly (image0.png, image1.png etc)

There are no stupid questions, only stupid people!

slickfish
web site design, production and maintenance for small business

www.justapickle.com
Blogging for the socially conscious

He has: 578 posts

Joined: Jun 2004

is there any way to make it choose words too?

He has: 578 posts

Joined: Jun 2004

I'm still getting nothing. Here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xml:lang="en">

<?php
   
function randImage() {
       
$number = rand(1,5);
        echo
"<img src=\"http://madclassifieds.000k.net/zap/imgs/headers/header\" . $number . \".png\" />";
}

?>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>zap graphics | pixel graphics that spark! | for the byond gaming system</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>

<body>
<div id="wrap">

<div id="nav">
<span class="bold">spark!</span>
<ul>
<li><a href="#" class="small">front</a></li>
<li><a href="#">contact</a></li>
<li><a href="#">work</a></li>
<li><a href="#">about</a></li>
</ul>
</div>

<div id="header">
<a href="index.html">
<?php
        randImage
();
       
?>

</a>
</div>
'

He has: 578 posts

Joined: Jun 2004

Woot. finally got it to work. I don't know how it's any different from yours, but it works!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.