#!/usr/bin/perl # # agent.pl # Copyright (c) 1996 SurfUtah.Com # written by Rus Berrett # # simple redirection script, based on browser # (see configuration section below) # ############################################################ # # Browser Configuration # # browser/URL pairs- "unique browser key", "URL" # the following is an associative array which is composed of # browsers in the "left" slots and URL's relative to your home # directory in the "right" slots. Replace the URL's for each # browser to match that of your server. If you need to add a # browser to the list simply put a unique part of the environment # variable, HTTP_USER_AGENT, in the left slot and the associative # URL in the left slot. If no match for the browser is found then # the "default" entry is used (don't delete the default entry and # don't put a comma after it either). Have fun! # # IMPORTANT: be sure your URL entries begin with a '/'. # @browsers = ( # MSIE (list MSIE in front of Mozilla since MSIE includes # "Mozilla" in its agent string- truly a Netscape wannabee) "MSIE", "/cgi/library/agent/test/msie_enhanced.html", # Netscape browsers. 1.0 can't do tables. You can collapse # all of the Netscape browsers into a single entry by using # the following line instead of the multiple lines below. # "Mozilla", "/cgi/library/agent/test/netscape_enhanced.html", "Mozilla/1.0", "/cgi/library/agent/test/non_enhanced.html", "Mozilla/1.1", "/cgi/library/agent/test/netscape_enhanced.html", "Mozilla/2", "/cgi/library/agent/test/netscape_enhanced.html", "Mozilla/3", "/cgi/library/agent/test/netscape_enhanced.html", "Mozilla/4", "/cgi/library/agent/test/netscape_enhanced.html", # Default, don't remove the entry and make sure it is last "default", "/cgi/library/agent/test/non_enhanced.html" ); # # end browser configuration # ############################################################ $home_ref = "http://$ENV{'SERVER_NAME'}"; $agent = $ENV{'HTTP_USER_AGENT'}; # Content type print "Content-type: text/plain\n"; # if no agent environment variable is present, redirect to default if ($agent eq "") { print "Location: $home_ref$browsers[$#browsers]\n\n"; exit(0); } # loop through the browsers for ($i=0; $i<$#browsers; $i+=2) { $key = $browsers[$i]; print "$key\n"; # skip the "default" entry. if ($key ne "default") { if ($agent =~ /$key/) { print "Location: $home_ref$browsers[$i+1]\n\n"; exit(0); } } } # no match, print out default print "Location: $home_ref$browsers[$#browsers]\n\n"; exit(0); ############################################################################## # eof agent.pl