Click here to return to Newclient Main Help Page


Back


Last Updated: February 25, 1998

Remote Agent Detection

One 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.

  1. The source code for remote agent detection
  2. Installation instructions


The Source Code for Remote Agent Detection

The 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 Detection

To install remote agent detection on your Virtual Server you will need to do three things:

  1. Modify your Server Resource Map and Access Configuration
    In order for the remote agent detection script to work properly, you server must be configured to recognize "agent.pl" as a valid directory index entry. Also, your server must allow the "agent.pl" to execute. If you are an BWSD Virtual Server customer, then these steps are easy (and outlined below. If you are not an BWSD customer (sign up!) then you should be able to follow along and simply modify the instructions to fit your server environment.

        Configuring Multiple Directory Index Entry

    • Telnet to your server and open the server resource map configuration file, "srm.conf", file found in your "www/conf" area, or if you have set up the iManager on your server, use its graphical interface to open the "srm.conf" file.

      Edit the "DirectoryIndex" such that "agent.pl" is the first definition entry. This will instruct the server to look for a "agent.pl" in a directory and if it is not found to look for the second file. Thus in the following example,

          DirectoryIndex   agent.pl index.html

      the server will check for the existence of the "agent.pl" script and if it is not present will then use the "index.html" file if present.

        Configuring Execution Access

    • In order for the HTML source to execute the "agent.pl" cgi, your server must be configured such that it recognizes cgi execution outside of the normal "cgi-bin" area. If you are a virtual server customer (each of whom control their own NCSA based httpd server with a complete set of configuration files) you can simply drop a ".htaccess" file into the directory where you store the "agent.pl" cgi. A sample ".htaccess" file is shown below:
            Options   Indexes FollowSymLinks Includes ExecCGI
            AddType   application/x-httpd-cgi .pl
            
  2. Download the Remote Agent Detection CGI source code
    You will need to download the file, agent.pl.

          If you are an BWSD customer

    1. telnet or SSH to your Virtual Server.
    2. change directories to your home directory (type "cd" and hit return)
    3. type "tar -xvf /usr/local/contrib/agent.tar"

          If you are not a BWSD AW Server customer (sign up!)

    1. Verify that a directory path "library/agent" exists in your "cgi-bin" area.
    2. Download the source file into your "cgi-bin/library/agent" directory and make sure the mode is set so that it will execute (chmod +x).

  3. Copy the agent.pl and .htaccess files into your document directory
    After you have installed the agent.pl script, you will need to copy it to the specific directory where you would like to include agent redirection. You will also need to put a copy of the ".htaccess" file (see the Configuring Execution Access section above) in the same directory. So for example, if you wanted agent detection capability in your main "htdocs" directory, you would want to copy the agent.pl file there by typing the following command:

    • cp ~/www/cgi-bin/library/agent/agent.pl ~/www/htdocs

  4. Create the HTML Source Associated with each Browser
    Create the HTML versions of your pages that will issued to each type of browser. Be sure to modify the source code (see above) so that each browser is associated with its proper URL.

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.

Agent Switch

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".


top


bd