|
Remote Agent DetectionOne way to insure that a seamless presentation is given to all clients that visit your web pages is to switch on the agent type (browser) and issue different HTML source (e.g. non-enhanced versus enhanced) to the client. A simple CGI and HTML file can be designed to facilitate such a task. The HTML file and CGI source are presented in two sections below.
The Source Code for Remote Agent DetectionThe source code for the Remote Agent Detection Script is written by Rus Berret. The browser configuration section of the source code should be changed to associate a URL with each browser (see instructions included in the source code). #!/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
If you are unfamiliar with the CGI standard, or would like to learn more about the Common Gateway Interface, the following URL is an excellent resource: http://hoohoo.ncsa.uiuc.edu/cgi/
How to Install Remote Agent DetectionTo install remote agent detection on your Virtual Server you will need to do three things:
Once you have completed the installation successfully, you will have a dynamic site that issues HTML source to clients based on the agent type (browser). An example of remote agent detection is given below.
You should be taken to a page that is customized for your browser, either the "MSIE Enhanced Page", the "Netscape Enhanced Page", or the "Non Enhanced Page".
|