#!/usr/local/bin/perl # # random - Choose a random file from a directory, and return a web server # redirect to that file. Used to display a different random image # each time you connect to a page. # # Written by Earl Fogel, August 1996 # # Configuration $DocumentRoot = $ENV{'DOCUMENT_ROOT'}; $ServerURL = "http://$ENV{'HTTP_HOST'}"; $Directory = "$DocumentRoot/images"; # this is just the default # Directory may be passed in as extra path info if you are very trusting # $Directory = $ENV{'PATH_INFO'} if $ENV{'PATH_INFO'} =~ /./; # $Directory = "$DocumentRoot/$Directory" if ! -d $Directory; chdir $Directory || die("Can't find directory: $Directory\n"); srand; # seed the random number generator @pool = <*.gif>; # list of gif files in $Directory $pick = int rand $#pool+1; # pick a random number $file = $pool[$pick]; # file corresponding to that number $newURL = "$Directory/$file"; $newURL =~ s#//#/#g; $newURL =~ s/$DocumentRoot/$ServerURL/e; print "Status: 303\n"; print "Location: $newURL\n\n";