#!/usr/local/bin/perl # Randomly picks a filename from $DIRSPEC and redirects the browser to it. # It sets the Expiration header so that the contents will have to be # retrived every time the user returns to the page or uses the Reload # button. # 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!.*/!!; # set the header & redirect user to the new location print "Location: $URL/".urlencode($file)."\n"; print "Date: ".httpdate(time)."\n"; print "Expires: ".httpdate(time)."\n"; print "Pragma: no-cache\n\n"; # that's all exit(0); # Encodes a string, changing most non-alphanumerics into %xx codes sub urlencode { my($s)=shift; $s=~s!([^a-z0-9\.\-])!sprintf("%%%02x",ord($1))!ige; return $s; } # Returns date & time string for use in HTTP headers: # Format: Sun, 15 Mar 1998 22:02:28 GMT sub httpdate { my($d)=shift; my(@l)=split(/\s/,scalar gmtime($d)); # change: Sun Mar 15 14:03:04 1998 # into: Sun, 15 Mar 1998 14:03:04 GMT return("$l[0], $l[2] $l[1] $l[4] $l[3] GMT"); }