SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict longroad's Avatar
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random image script

    Im trying to incorporate this script into my site, from the Sitepoint article:
    http://www.sitepoint.com/article/pic...wcase-php-html

    I've done everything as it says, just changing the image names to suit my own.
    However the images do not rotate. I am using this for one image only, not the gallery set up. I've tried with one image and several images though, and still the images stay static and do not rotate despite me changing the secondsFixed value.

    I cant see why this would be happening as its a very simple script to set up.

    Any ideas?

  2. #2
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got some code?

  3. #3
    SitePoint Addict longroad's Avatar
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <?php
    // rotate images randomly but w/o dups on same page - format:
    // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1'
    // for second, etc
    // (c) 2004 David Pankhurst - use freely, but please leave in my credit
    $images=array( // list of files to rotate - add as needed
     "homepic.jpg",
     "exposure1.jpg",
     "exposure1.jpg",
     "exposure1.jpg",
     "image001.gif",
     "image002.gif",
     "images1.jpg");
    $total=count($images);
    $secondsFixed=2; // seconds to keep list the same
    $seedValue=(int)(time()/$secondsFixed);
    srand($seedValue);
    for ($i=0;$i<$total;++$i) // shuffle list 'randomly'
    {
     $r=rand(0,$total-1);
     $temp =$images[$i];
     $images[$i]=$images[$r];
     $images[$r]=$temp;
    }
    $index=(int)($_GET['i']); // image index passed in
    $i=$index%$total; // make sure index always in bounds
    $file=$images[$i];
    header("Location: $file"); // and pass file reference back
    ?>
    HTML simply has this in it:
    Code:
    <img src='rotate.php?i=0'>
    Ive also tried it with
    Code:
    <img src='rotate.php?i=0'>
    <img src='rotate.php?i=1'>
    <img src='rotate.php?i=2'>
    but same problem (no rotation occurs)

  4. #4
    SitePoint Addict longroad's Avatar
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any ideas anyone?
    this is urgent so would appreciate any help

  5. #5
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've seen better scripts myself. I couldn't get it to rotate images as described either.

    One way to get this one to work is to put a meta refresh in between your <head></head> tags, something like this:

    Code:
    <META HTTP-EQUIV=Refresh CONTENT="2">
    If you want rotating images, a slide show script would probably be much better. I could probably dig up one of those if you were interested.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •