Home > Perl Reference > Examples > Redirection
This script redirects the person to a certian website. This
script is good if you have any links to other sites, sponsors
ect.
Ths script uses Query Strings. Below is a example of a link using
this script.
http://yourdomain.com/cgi-bin/redirect.pl?http://www.yahoo.co.uk
See the script in action by click on this link :
http://htmlstudio.virtualave.net/cgi-bin/redirect.pl?http://htmlstudio.virtualave.net/perl/examples/redirect.html
The Code
Paste the code below into a text editor and save it as
redirect.pl You can edit the script to suit your needs
e.g The number of seconds before the user gets redirected. Upload
the script into your cgi bin. Upload it as ASCII.
Please make it so #!/usr/bin/perl is the location of perl on your server.
#!/usr/bin/perl
$url = $ENV{'QUERY_STRING'};
$advert = '<i>Brought to you by Html Studio,
Inc.</i><br>';
$font_style = '<font face="Tahoma,Arial"
size="2">';
##### You do not have to edit any code below this line #####
&Print_Output;
sub Print_Output {
print "Content-type: text/html\n\n";
print <<"END";
<html><head>
<meta http-equiv="Refresh" content="5;
URL=$url">
<title>One Moment... $url</title>
</head>
<body bgcolor="WHITE">
<p>
<center>$advert</center>
<blockquote>
$font_style
<b>Please wait, taking you to: </b><br>
<b>$url</b><br>
<a href="$url">
<br>Click here if you are not redirected within a few
seconds.</a>
</body>
</html>
END
}
Maintained by Nick Grant < htmlstudio@talk21.com >
Copyright © 2000 Nick Grant. All Rights Reserved.