Smart Redirection

Redirect browser to a different random URL each time.

Script 8: random_pict.pl

 #!/usr/local/bin/perl
 # script: random_pict.pl

 use CGI qw/:standard/;
 $PICTURE_PATH = path_translated();
 $PICTURE_URL = path_info();
 chdir $PICTURE_PATH
  	or die "Couldn't chdir to pictures directory: $!";
 @pictures = <*.{jpg,gif}>;
 $lucky_one = $pictures[rand(@pictures)];
 die "Failed to pick a picture" unless $lucky_one;

 print redirect(
	       -uri=>"$PICTURE_URL/$lucky_one",
	       -expires=>'-1m',
	       );

What it Looks Like

Try reloading this page a few times!

<img src="http://localhost/cgi-bin/conference/random_pict.pl/icons/">

<< Previous
Contents >> Next >>

Lincoln D. Stein, lstein@cshl.org
Cold Spring Harbor Laboratory
Last modified: Sat Jun 19 12:37:06 EDT 1999