<?php
    
//Random Sig Image Script (c)2004 r1ch.net
    //Released as public domain.

    //CONFIGURATION: Fill in this directory with the relative
    //path of where your images are. Eg if the script is in
    ///blah/random.php and your images are in /blah/images/
    //then set $imagedir = "images/" (trailing slash is important!)

    
$imagedir "images/";

    
//Turn off errror reporting since we handle it ourselves
    
error_reporting (0);

    
//Get directory handle
    
$dir opendir($imagedir) or die ("Couldn't open $imagedir\n");

    
$num_images 0;
    
$images = array();

    
//Scan through it
    
while ($entry = (readdir($dir)))
    {
        
//Is it an image?
        
if (!preg_match ("/\.(png|jpg|jpeg|gif)$/i"$entry))
        {
            continue;
        }
        
        
//Add image to array
        
array_push ($images$entry);
        
$num_images++;
    }

    
//Close handle
    
closedir ($dir);

    if (!
$num_images)
    {
        die (
"No images in $imagedir\n");
    }

    
//Seed random number generator
    
srand (time());

    
//Generate a random number
    
$num intval(rand (0$num_images-1));

    
//Print redirect header to new image
    
header ("HTTP/1.0 303 See Other");
    
header ("Cache-Control: no-cache");
    
header ("Location: $imagedir$images[$num]");
?>