Intranet Journal
Perl/CGI

  •   Home
  •  Getting Started
  •  Intranet Development
  •  Info Management
  •  Columns & Advice
  •  Case Studies
  •  Security
  •  Intranet FAQ
  •  Discussion Board
  •  Events Calendar
  •  Intranet Books
  •  Tools of the Trade
  •  Tutorials
  •  Features
  •  Site Map


Free Newsletter!
 
Privacy Policy

Search
Intranet Journal:




www.internet.com
IDM Top Twenty Articles

  1. Wearable Computers Get Web Content Management
  2. JavaScript FAQ
  3. VBScript Tutorial
  4. Dreamweaver Tutorial
  5. Putting Your Intranet to Work: 50 Ideas for Department-Specific Applications
  6. P.G. Daly's Intranet Talk: Basic Intranet Guidelines and Standards
  7. The Intranet FAQ
  8. Are You Ready for the Next-Generation Intranet: Making Your Intranet a Dynamic Knowledge Base
  9. Intranet Corner Knowledge Management 101
  10. Content Management Made Easy with ASP
  11. JavaScript Forms and Frames
  12. Untangling Web Content Management
  13. Working Together, Apart: The Web as Project Infrastructure
  14. Cascading Style Sheets Tutorial Part II
  15. A FrontPage Tutorial
  16. Free PDA Content Syncing Hits the Airports
  17. Introducing Microsoft DotNet
  18. The Elements of Intranet Style
  19. The Rise of Web Services: Completing the Picture
  20. The five-step process to implement Intranet to Manage your Strategic Information

See Intranet Journal's Page in
Yahoo logo
internet.com

internet commerce

Be a Commerce Partner

* [ Home | eXchange | F A Q | Search ]     Saturday November 7, 2009

Browser Redirection with Perl

By Jonathon Miller

Jonathon shows us how to work around browser incompatabilities.

If there is one major problem with the Web today, it is the fact that those who develop for it must work around browser incompatibilities. These differences are not just between the newest versions of competing software, such as Navigator and Internet Explorer, but also among different versions from the same company. Web developers are often left with broken tables, defunct style sheets, and Dynamic HTML that is anything but dynamic.

If you know what your reader is using to view your pages, they can be designed to take maximum advantage of that technology, no matter what the level. Browser detection is the best way to ensure your message is coming across the way you envisioned it.

That's where we come in.

The most common way of detecting a visitor's browser is via an index.cgi file written in perl.

Let's get started on that script.

	#!/usr/local/bin/perl 

The first line of any friendly perl script is the location of the perl compiler. A common variation of the above is #!/usr/bin/perl. To locate your perl compiler, issue the command which perl at the Unix prompt.

	($TEST = $ENV{'HTTP_USER_AGENT'}); 

This next line grabs the HTTP_USER_AGENT environment setting from your browser and stores it in the variable $TYPE. This environment setting is the equivalent of clicking the help/about menu item on your browser, bringing up the name and version number of the client you use to surf the net.

	$netscape_3 =    "http://www.yoursite.com/netscape3/";
	$netscape_4 = "http://www.yoursite.com/netscape4/";
	$iexplorer = "http://www.yoursite.com/ie/";
	$lynx =    "http://www.yoursite.com/lynx/";
	$aol =    "http://www.yoursite.com/aol/";

These five lines setup a URL for each browser you wish to test for. This will become more clear after reading the following code:

	$browser = $netscape_3 if $TEST =~ /Mozilla/3/;
	$browser = $netscape_4 if $TEST =~ /Mozilla/4/;
	$browser = $lynx if $TEST =~ /Lynx/i;
	$browser = $iexplorer if $TEST =~ /microsoft/i;
	$browser = $aol if $TEST =~ /aol/i;

If you remember, we set $TEST equal to whatever string the browser returned when we asked for its version. In this snippet of code, we search $TEST for certain words associated with different browsers, such as 'microsoft' or 'aol' and set $BROWSER accordingly.

	print "Location: $browser";

The final line of our script simply sends the reader to the URL specified in the string $browser, and then exits.

	#!/usr/local/bin/perl 
	($TEST = $ENV{'HTTP_USER_AGENT'});
	$mysite = "http://url.to.your.site";
	$netscape_3 = "$mysite/netscape3/";
	$netscape_4 = "$mysite/netscape4/";
	$iexplorer = "$mysite/ie/";
	$lynx = "$mysite/lynx/";
	$aol =   "$mysite/aol/";
	
	$browser = $netscape_3 if $TEST =~ /Mozilla/3/;
	$browser = $netscape_4 if $TEST =~ /Mozilla/4/;
	$browser = $iexplorer if $TEST =~ /microsoft/i;
	$browser = $lynx if $TEST =~ /Lynx/i;
	$browser = $aol if $TEST =~ /aol/i;
	
	print "Location: $browser"; exit(); 

Simply insert that into a text file named index.cgi and you're all finished. Welcome to the wide world of browser redirection. (You will need to chmod 755 index.cgi)

How can I customize my site for each user? >

Of Interest
· JavaScript FAQ
· Web Development Tools

 Intranet News 
* Intranet/Internet Product Summary: January 04, 2001
* Red Herring Picks Plumtree for Employee Portal
* Tideworks Goes with Intranet from Eprise
* Crayfish Nabs 47 Percent of Intranets.com's Japan Arm
* IntraNet Solutions Notches Belt with Oakwood
* BT Secures Corporate Portal Help from Plumtree
* Mobilize Offers Enterprise App to Lexis-Nexis

More News

In' tra net - n. 1) a computer network connecting an affiliated set of clients using standard internet protocols, esp. TCP/IP and HTTP. 2) an IP-based network of nodes behind a firewall, or behind several firewalls connected by secure, possibly virtual, networks.
  IDM Unwired  
IDM on the Road
NOW AN OFFICIAL AVANTGO CHANNEL!
To easily add IDM to your PDA
click here

Featured Archive Articles

  •  Putting Your Intranet to Work: 50 Ideas for Department-Specific Applications
  •   Five-steps to implement your intranet and manage your strategic information
  •  A new generation of intranet tools intersects Customer Relationship Management and Sales Force Automation
  •   Business Intelligence and the Intranet
  •  Effective Intranet Publishing: Getting Critical Knowledge to Any Employee, Anywhere


  •   Using an Intranet to Manage 610,000 animal specimens with Java
  •  Putting JavaScript to Work for Your Intranet
  •   JavaScript Forms and Frames
  •  Introduction to the Browser Object Model
  •  Black Hole Sun: Java is Going Supernova Thanks to its Creator's Gravitational Pull


  •   Managing Large Collections of Documents: A full-length excerpt from the book "Intranet Document Management."
  •  Intranet Traffic Management: Without Quality of Service standards, intranets and extranets face death by success
  •  Issues in Intranet Security: A primer on keeping the keys to the enterprise safe


  •   Report from the trenches: Firms weigh in on intranet deployment trends
  •  The Magna Carta of the Intranet: From Smart Companies, Smart Tools
  •   Prudential HealthCare Launches Extranet to Manage Health Benefits
  •   Wells Fargo Unit Looks To Establish Its Intranet as a 'Portal'
  •   Amkor/Anam's intranet is a study in open systems integration


  •  Tutorial: Finding Your Way Around E-commerce
  •   The Essential Supply Chain
  •  A Definition of Data Warehousing
  •   Internet Messaging: from the Desktop to the Enterprise


  •  Improving Intranet Information Retrieval with Human Indexing
  •   An XML Development Kit
  •   When To Use Active Server Pages
  •  Intranets and extranets for virtual project management
  •  Why Groupware is Hard
  •  Optimizing Web Pages For Handheld Devices


  •  Version Control within a Collaborative Extranet
  •   Electronic Procurement, Extranets and You
  •  Intranet and extranets for virtual project management
  •  Overview of Virtual Private Networks


  •  What's the Future of Application Service Vendors?
  •  'Enterprise Portal' - a New Catch Phrase, But Definitions Vary
  •   Portals, You Say? This One's Private Ericsson's intranet is a give-and-take affair with employees
  •  Application Hosting

Elsewhere on internet.com
*  What Happened at XML 2000?
*  Collaborative Computing: This Changes Everything
*  inFusion: Bringing ColdFusion to a Mail Server Near Youn
*  Netscape 6, Part I: Detection and Scripting
*  AOL Introduces Mobile Communicator
*  NetMenu2
*  Bluetooth Security
*  DHTML Hiermenus 4.0: The Page-Specific Parameters
*  XML Content Syndication: Part 2
*  HardwareCentral Update: Intel's Pentium 4, a New Architecture Unveiled


Copyright 2002 Jupitermedia Corporation, All Rights Reserved.
Legal Notices | Licensing, Reprints, & Permissions | Privacy Policy | Advertising on Intranet Journal
Home | eXchange | F A Q | Find | Register |