help me random-image.php code

Discussion in 'PHP' started by 1why, Jan 2, 2007.

  1. #1
    Please help
    -------------------------------------------------
    a-image.gif
    b-image.gif
    c-image.gif
    d-image.gif

    I need to place <img src="random-image.php" > to other websites

    so it can load x-image.gif (x can be a, b ,c or d)

    need to work for IE and FF (browser)
    -------------------------------------------------
    Does any one know how to write the random-image.php code?

    Thank you
     
    1why, Jan 2, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php
    
    $prefixes = range('a', 'd');
    $image = $prefixes[array_rand($prefixes)] . '-image.gif';
    
    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: image/gif');
    
    readfile($image);
    
    ?>
    
    PHP:
    Untested.
     
    nico_swd, Jan 3, 2007 IP
    1why likes this.
  3. 1why

    1why Peon

    Messages:
    68
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Nico_swd,

    It is very helpful.

    Thank you
     
    1why, Jan 3, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I just fixed a llittle typo, incase you didn't see it yet. :)
     
    nico_swd, Jan 3, 2007 IP