#!/usr/bin/perl

# Browser Detection/Redirection Program
# Version 1.2
# browsertest.pl
# By Mike Calabrese
# http://www.mikecalabrese.com/index.shtml
# 11-23-2004

# This program is available for free on an AS-IS basis.  I am not
# responsible for consequential damages, loss of income or whatever
# else that may happen as a result  of the use of this program.

# Take in the input
$theinput = <>;

# Write their user agent string to the useragents file
&write_to_useragents;

# Search the user_agent string for the browser version
$useragent = ($ENV{HTTP_USER_AGENT});
chomp $useragent;

# Redirect the output to the proper web page
# browser1 = Netscape
# browser2 = Firefox
# browser33 = IE
# browser66 = Opera
# browser75 = Safari
# browser99 = Unknown browser

if (($useragent) =~ (/Opera/i)) {


print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<META HTTP-EQUIV=refresh CONTENT=1\;URL=http://www.yourdomain.com/exact/url/path/to/browser66.html>\n";
print "<title></title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "</BODY></HTML>\n";
}

elsif (($useragent) =~ (/MSIE/i)) {


print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<META HTTP-EQUIV=refresh CONTENT=1\;URL=http://www.yourdomain.com/exact/url/path/to/browser33.html>\n";
print "<title></title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "</BODY></HTML>\n";
}

elsif (($useragent) =~ (/Firefox/i)) {


print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<META HTTP-EQUIV=refresh CONTENT=1\;URL=http://www.yourdomain.com/exact/url/path/to/browser2.html>\n";
print "<title></title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "</BODY></HTML>\n";
}

elsif (($useragent) =~ (/Safari/i)) {

print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<META HTTP-EQUIV=refresh CONTENT=1\;URL=http://www.yourdomain.com/exact/url/path/to/browser75.html>\n";
print "<title></title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "</BODY></HTML>\n";
}

elsif (($useragent) =~ (/Netscape\/*\[*\]*\(*\)*/i)) {

print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<META HTTP-EQUIV=refresh CONTENT=1\;URL=http://www.yourdomain.com/exact/url/path/to/browser1.html>\n";
print "<title></title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "</BODY></HTML>\n";
}



elsif (($useragent) =~ (/Mozilla\/*\[*\]*\(*\)*/i)) {

print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<META HTTP-EQUIV=refresh CONTENT=1\;URL=http://www.yourdomain.com/exact/url/path/to/browser1.html>\n";
print "<title></title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "</BODY></HTML>\n";

}else{

print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<META HTTP-EQUIV=refresh CONTENT=1;URL=http://www.yourdomain.com/exact/url/path/to/browser99.html>\n";
print "<title></title></head>\n";
print "<body bgcolor=#ffffff text=#000000 link=#008000 vlink=#400000>\n";
print "</BODY></HTML>\n";
}


sub write_to_useragents {
(open(OUTFILE,">>/exact/UNIX/path/to/useragents"));
print OUTFILE ("$ENV{HTTP_USER_AGENT}\n");
}