#!/usr/local/bin/perl # Randomly picks a filename from $DIRSPEC and returns it # It doesn't set the Expiration: header, so most web browsers will # probably not actually run this script more than once. # # where to search for the files $DIRSPEC="/home/httpd/html/web/*.{gif,jpeg,jpg}"; # URL where where the files are served from # example: http://yoursite.com/dirname $URL="/web"; # get a list of all the files @list=glob($DIRSPEC); # pick a random file name from the list $file=$list[ (time&0xffff ^ $$) % ($#list+1) ]; # remove path from the name $file=~s!.*/!!; # redirect user to the new location print "Location: $URL/".urlencode($file)."\n\n"; # that's all exit(0); # encodes a string, encoding non-alphanumerics into %xx codes sub urlencode { my($s)=shift; $s=~s!([^a-z0-9\.\-])!sprintf("%%%02x",ord($1))!ige; return $s; }