Remote Agent DetectionLast Updated: November 17, 1998One 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 the sections below.
The Source Code for Remote Agent DetectionThe source code that handles the remote agent detection has been released to the public domain. 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
#
# 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",
# Default, don't remove the entry
"default", "/cgi/library/agent/test/non_enhanced.html"
);
#
# end browser configuration
#
############################################################
$home_ref = "http://$ENV{'SERVER_NAME'}";
$agent = $ENV{'HTTP_USER_AGENT'};
# if no agent environment variable is present, redirect to default
if ($agent eq "") {
print "Location: $home_ref$browsers{'default'}\n\n";
exit(0);
}
# loop through the browsers
foreach $key(keys %browsers) {
# skip the "default" entry.
if ($key ne "default") {
if ($agent =~ /$key/) {
print "Location: $home_ref$browsers{$key}\n\n";
exit(0);
}
}
}
# no match, print out default
print "Location: $home_ref$browsers{'default'}\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".
|
Copyright © 1996, 1997. A Little Technology Shoppe, LLC. All rights reserved. All brand names and product names used on these web pages are trademarks, or trade names of their respective holders.