the complete webmaster
tutorials reviews reference
ASP
CGI
FrontPage
HTML
Java
JavaScript

Sponsored by El Scripto

Visit the Mortgage Loan Place for Home Loans and also click here to find VA Loans on our site.

Promote your website

home / articles / cgi

...and the Browser Wars Continue

As you know, a lot of attention is being given to the battle for the world's most popular web browser. Hopefully, many browsers will continue to be available, thus giving users a wide range of choices. Everyone has distinct tastes, and one company's browser cannot be right for every user in the world.

Everyone, however, wonders how popular certain browsers are. If you look through your web server's logs, you'll find that the "HTTP_USER_AGENT" gives you a hint as to which browser is being used. Values for USER_AGENT look something like the following:

  1. Mozilla/4.04 [en] (X11; U; Linux 2.0.30 i586)
  2. Mozilla/3.0 WebTV/1.2 (compatible; MSIE 2.0)
  3. Mozilla/2.0 (compatible; MSIE 3.0; AOL 3.0; Windows 3.1)
  4. Mozilla/2.0 (compatible; MSIE 3.0B; Win32)
  5. Mozilla/4.01 (Macintosh; I; PPC)
  6. Enhanced_Mosaic/2.10R9.1 Win32 FTP Software/Spyglass/9.1
  7. PRODIGY-WB/3.2d
  8. NCSA Mosaic/2.0 (Windows x86)
  9. SafeSearch Robot/1.0 libwww/unknown
These tell you the type of web browser that is currently requesting a resource from your web server. Here's what each one means:
  1. U.S. English version of Netscape Communicator version 4.04 running under X11 on Linux (kernel version 2.0.30). The processor is a Pentium or compatible (i586).
  2. WebTV version 1.2 client. It claims to be using Microsoft Internet Explorer(MSIE) version 2.0 and is also compatible with Netscape 3.0 (Mozilla/3.0).
  3. Microsoft Internet Explorer 3.0 running on Windows 3.1 and using America Online(AOL) version 3.0. It is compatible with Netscape 2.0 (Mozilla/2.0).
  4. Microsoft Internet Explorer 3.0B, possibly running on Windows NT or 95; compatible with Netscape 2.0 (Mozilla/2.0).
  5. Netscape Communicator 4.01 running on a Macintosh with a PowerPC processor.
  6. Spyglass Mosaic running on Windows NT or 95.
  7. Prodigy's web browser version 3.2d
  8. NCSA Mosaic version 2.0 running on Microsoft Windows.
  9. Not a user, but a web searching robot

Trying to figure out what type of browser is being used can be a complex task. Trying to keep score of which browser is most popular adds another level of complexity to the problem.

This week's script provides a simple way to track and display how the browser battle is faring on a web page near you. First, to reduce complexity of the script, only four distinct USER_AGENTs are detected:

  • Netscape Navigator & Communicator
  • Microsoft Internet Explorer
  • Microsoft's WebTV
  • All Others
Ideally, we'd like to count each user only once. In other words, if someone who uses MSIE 3.0 reloads the page twenty times, we don't want to count MSIE twenty times. Without sending the user a cookie, however, there's no easy way to guard against this possibility. The approach taken here is to check the IP address that last used MSIE and only count the hit if it's different. This is a fast and simple solution.

Also, it's important to know about proxies. A proxy is a special piece of software that sits between a user's machine and your web server. The user connects to the proxy, then the proxy connects to your web server.

User --> Proxy --> Web Server

The proxy may change the USER_AGENT variable or it may leave it alone. Because many users use one proxy and each proxy has one IP address, the script will undercount the number of users.

To use this script, you'll need to enable Server Side Includes in your web server. To learn about Server Side Includes (SSI) in Apache, check out these references:

Next, you'll need to obtain the Perl script: Save the perl script to a safe place. Next, make the script executable:
  • chmod a+x /path/whatbrowser.pl
Before running the script, edit the following part of whatbrowser.pl:

# path and name for the access log
$logfile="/tmp/access.txt";

Change path and name to point to where you want to store the data file. After selecting a suitable location, issue the following commands to make sure the file can be read and written by your web server daemon:

  • touch /path/access.txt
  • chmod a+rw /path/access.txt

Next, after enabling SSI, add the following code to an HTML file:

<!--#exec cmd="/path/whatbrowser.pl"-->

Change the /path to point to the directory where you stored the script. With luck, you should have something like the following on your web page:

Browser'A' 85%
   
Browser'B' 15%
   

Every time someone looks at the page, the results will be updated. Now, you'll always know how the battle for the most popular web browser is going on your web site.

Note: This program has been tested on many flavors of Unix running the Apache web server. It may not, however, work correctly on all web servers, especially non-Unix ones.

Author: Doug Steinwand
Date: [12/09/97]
More articles about CGI
More articles by Doug Steinwand
Author Biography
Get more website traffic
write for us about us advertise

Copyright 1997, 1998 A Big Lime. All rights reserved.