Access Advocates

i n t e r n e t  c o n s u l t a n t s

Redirect List Tutorial


This tutorial shows you how a simple CGI program creates a nifty way to let visitors jump to any area of your website. I'll even show you how to speed things up with a snippet of JAVA. You need to have access to a common program called "redirect.pl" in your webserver's cgi-bin, or the ability to add the program.

Redirect Lists in Action

The first example shows a redirect list that allows you to select a destination and press "Submit" to jump to that URL. The second list uses an image instead of a submit button. The third example adds a line of JAVA that causes the browser to immediately jump to the selected URL.

HTML Code for Redirect Lists

<form method="POST" action="/cgi/redirect.pl">
<select name="url">
<option value=""> Select a Page to Visit
<option value=""http://url.one/"> URL One
<option value="http://url.two/"> URL Two
<option value="http://url.three/"> URL Three
</select>
<input type=submit name=submit value="Submit">
</form>

The first line of the HTML code will probably work for your server, but if you don't keep your executable files in /cgi/ it might need to be changed to indicate the correct directory. The "Submit" button can be labelled with any value you please. To use an image instead of a submit button, substitute the following "input" line:

<input type=image border=0 src="image.gif">

JAVA-based automatic redirection, shown below, only works on JAVA-enabled browsers, which include 72% of the market based on our August 1998 log files. To make the redirection automatic for JAVA-enabled browsers, substitute the following "select" line:

<select name="url" onChange="submit(); return true">

The Perl Script

You might already have access to a redirect.pl script. Try the HTML code above and see if it works! If not, you will need to copy the Perl script below to a file called "redirect.pl" in your cgi-bin (or whatever you call it -- mine is just "cgi"). Change the permissions (chmod 755 redirect.pl) and edit the first line of redirect.pl to reflect the location of Perl on your server.
#!/usr/bin/perl
# NOTE: Modify the first line to point to the local Perl program.
# 
# redirect.pl
#
read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
# Parse name-value pairs and de-webbify.
@key_value_pairs = split(/&/, $query_string);
foreach $key_value (@key_value_pairs) {
 ($key, $value) = split (/=/, $key_value);
 $key =~ tr/+/ /;
 $value =~ tr/+/ /;
 $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex($1))/eg;
 if (defined($array{$key})) {
 $array{$key} = join("|", $array{$key}, $value);
 } else {
 $array{$key} = $value;
 }
} 
if ($array{'url'} eq "") {
 print "Status: 204 Do Nothing\n\n";
 exit(0);
}
elsif ($array{'url'} !~ /^http/) {
 $prefix = "http://" . $ENV{'SERVER_NAME'};
 if ($ENV{'SERVER_PORT'} ne "80") {
 $prefix .= ":" . $ENV{'SERVER_PORT'};
 }
 if ($array{'url'} !~ /^\//) {
 $prefix .= "/";
 }
 $array{'url'} = $prefix . $array{'url'};
}
print <<EOF;
Content-type: text/html
Location: $array{'url'}

EOF


This Redirection List Tutorial is just one example of the expertise of our staff. Want to learn more? Contact us for more information!


Want Redirection? Access Advocates.
Satisfaction guaranteed!

Home | Websites | Graphics | Promotion | Programs | Hints | Portfolio | Contact

Copyright © 1995-2002 Access Advocates Internet Consultants