Determining the User Agent and Printing the Appropriate Result : Environment Variables « CGI « Perl






Determining the User Agent and Printing the Appropriate Result

    


#!/usr/bin/perl -T

use strict;
use CGI qw/:standard/;

my $useragent = $ENV{'HTTP_USER_AGENT'};

print header,
start_html('User Agent Example');
if ($useragent =~ /Firefox/) {
    print p("You are visiting with a Firefox browser");
} elsif ($useragent =~ /MSIE/) {
    print p("You are visiting with an Internet Explorer browser");
} else {
    print p("Could not determine browser: $useragent");
}
print end_html;

exit;

   
    
    
    
  








Related examples in the same category

1.Display CGI environment variables
2.Viewing Environment Variables in a CGI Script
3.CGI Environment Variables
4.Learn about the server for a CGI request
5.Program to display CGI environment variables.
6.$ENV{'HTTP_USER_AGENT'}, $ENV{'SERVER_PROTOCOL'}, $ENV{'HTTP_HOST'}
7.Get and display the browser type by referencing HTTP_USER_AGENT
8.Server Environment Values
9.CGI request-related environment variables
10.CGI server-related environment variables
11.CGI client-related environment variables
12.HEADER DESCRIPTION
13.Display all values in env
14.CGI Environment Variables (Must Be Uppercase)
15.CGI environment variable
16.An example of using QUERY_STRING.