I need to create a Perl CGI script that will accept a single parameter as input. The parameter will be a fully qualified URL and the script will redirect the browser to the URL that has been passed as the parameter. The method is a GET and not a POST.
The browser address bar will accept the full script with the URL parameter like this: http://webserver/cgi-bin/myscript.pl?URL=http://www.google.com
I am new to Perl and I can figure out how to do it with a POST, but not a GET. Any help would be greatly appreciated.
I stole this code but it does not do a GET and I think I am using a bad example or one that does not apply to what I need to do:
UPDATE: This was my solution
#!/usr/local/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use DBI;
use URI::Escape;
use strictures;
use CGI;
use URI;
my $q = new CGI ;
my $url = "httpcandy";
# Process an HTTP request
#my @values = $q->multi_param('form_field');
my $value = $q->param('param_name');
print "Content-type: text/html\n\n";
#print "<pre>\n";
#
#foreach my $key (sort keys(%ENV)) {
# print "$key = $ENV{$key}<br/>";
#}
#print "</pre>\n";
my $requested = URI->new( CGI::url() );
$requested->query( $ENV{QUERY_STRING} || $ENV{REDIRECT_QUERY_STRING} )
if url_param();
#print header(),
# start_html(),
# h1("requested:"),
# blockquote($requested),
# h1("url:"),
# blockquote($value),
# h1("nothing else"),
#
# end_html();
#
if ($value =~ /http/)
{
print "<META HTTP-EQUIV=refresh CONTENT=\"1;$value\">\n";
}
else
{
print "<META HTTP-EQUIV=refresh CONTENT=\"1;URL=http://$value\">\n";
};
exit;
POST” yet your code uses a constant redirect URL, and not a parameter. Please can you show your working code?