Print this Article (NS4)
Netscape Navigator
Internet Explorer
Opera
Neoplanet

Forums
HTML
General
Site Dev
Programming
Flash
Grafix (Art)

Laboratory
Smart HTML
Color Lab
Generators

Contents
Simple CGI
  1. Hello World
  2. Print function
  3. Quoting, EOF
  4. Metacharacters
  5. Special Characters
Perl Basics 1
  1. Variables
  2. Arrays
  3. Hashes
  4. Split function
  5. Subroutines
  6. Defaults
Form CGI
  1. Loops
  2. Conditions
  3. Boolean Statements
  4. Pattern Matching
Time CGI
  1. Local Time
  2. GM Time
  3. time function
Perl Basics 2
  1. Reading Files
  2. Writing Files
  3. Including Files
  4. chop function
  5. chomp function
Guestbook CGI

Redirect CGI

Poll CGI

  1. Giving Commands
  2. Voting
  3. Results Display
  4. Adding Your Vote
Password CGI
  1. Authentification
  2. Multiple Users
  3. Encryption
Mailing List CGI
  1. Sendmail
  2. Multiple Recipients
Unlimited Subdomains CGI

News Grabber CGI

  1. LWP::Simple
Message Board CGI (Part 1)

Back to the Top


Perl Case Study - Redirect CGI
By Lisa Hui

This case is pretty simple; there is only one essential line that will make this script redirect to another URL (or page). The following basic script will do just that:

#!/usr/local/bin/perl
#######################
# File: redirect.cgi

$url = "http://3dinfinity.com/aiw/"; # destination of the redirection

print "Location: $url\n\n";


See this script in action: redirect.cgi

What did that do? It just sent you to a predefined URL. The important line was printing "Location: URL\n\n" which is the whole mechanism that redirected you to the URL. I set it as a variable so that you can use other routines to predetermine the redirection destination.

For example, you can have the script take in an environment variable, like $ENV{'QUERY_STRING'} (redirect.cgi?TheQueryString), and based on that information, select a link from a list or hash you define in a script or in a file. You can even open a file and get the necessary information before computing and deciding what the URL destination should be.


Perl Case Study - Poll CGI

©1999 Team 26297 "Ad Infinitum Web." All rights reserved. Any reproduction of this document for commercial or redistribution purposes without the permission of the author is forbidden.