#!/usr/bin/perl -w # redirect.pl - redirects a browser to the URL contained in QUERY_STRING # by Jonathan Eisenzopf. v1.0 19990818 # Copyright (c) 1999 Jupitermedia Corp. All Rights Reserved. # See http://www.webreference.com/perl for more information # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. use strict; use CGI; use CGI::Carp; use URI; # CONSTANTS my $restricted = 1; my %ok_hosts = ('www.webreference.com' => 1, 'www.internet.com' => 1, 'www.webdeveloper.com' => 1, 'www.wdvl.com' => 1, 'eisen.textant.com' => 1 ); # MAIN my $q = new CGI; # print error if QUERY_STRING is empty &error("Must specify URL") unless defined $q->keywords; # print error if there is no HTTP referer &error("Cannot run script directly") unless defined $q->referer; # get referer URL my $referer = new URI($q->referer); # print error if $restricted is on and referer is not in @ok_hosts &error("Host ".$referer->host." is not allow to redirect") if $restricted && !exists($ok_hosts{$referer->host}); # redirect print $q->redirect($q->keywords); # SUBROUTINES sub error { my $message = shift; print $q->header; print "

$message

"; die "$message"; }