CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Probably an easy one... redirect.pl server error, can't use script!

 



rcrx3
Novice

Jan 5, 2009, 6:12 PM

Post #1 of 17 (2317 views)
Probably an easy one... redirect.pl server error, can't use script! Can't Post

Hi Folks,

I hate to make my first post on any forums a cry for help, but I would be much appreciative to anyone who may shed some specific light on my problem.

I'm trying to use a simple html form to create a drop-down list redirect function using the redirect.pl script. I have uploaded the script correctly, and it has been CHMOD'd to 0755.

You may see what the error is doing here: http://www.fitnessopus.com/xcart/home.php - the dreaded 500 internal server error.

Here is the redirect.pl script, and the html I'm embedding in a .tpl file as part of a php software template called x-cart:

(This has extraneous information in it)


[the following is the Perl script]

#!/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'}
}
print "Content-type: text/html\n\n";
}
EOF


[end Perl script]










here is the html code embedded in the .tpl file:





<style type="text/css">
<!--
.button_submit {
text-align: center;
}
-->
</style>
{* $Id: categories.tpl,v 1.26 2005/11/17 06:55:37 max Exp $ *}
{capture name=menu}
<table cellpadding="0" cellspacing="0" {if $main eq "catalog" and $current_category.category eq ""}class="CategoriesCustomBox"{else}width="100%"{/if}>
<tr>
<td valign="top">

{if $active_modules.Fancy_Categories ne ""}
<table cellpadding="0" cellspacing="0" {if $main eq "catalog" and $current_category.category eq ""}class="CategoriesCustomBoxFC"{else}width="150"{/if}>
<tr>
<td valign="top">
{include file="modules/Fancy_Categories/categories.tpl"}
{assign var="fc_cellpadding" value="0"}
</td>
</tr>
</table>
{else}
{if $config.General.root_categories eq "Y"}
{foreach from=$categories item=c}
{if $main eq "catalog" and $current_category.category eq ""}
{capture name=bullet}<a href="home.php?cat={$c.categoryid}" class="VertMenuCatWelcItems">{$c.category}</a>{/capture}{include file="customer/main/bullet.tpl" content=$smarty.capture.bullet welc=true}
{else}
{capture name=bullet}<a href="home.php?cat={$c.categoryid}" class="VertMenuCatItems">{$c.category}</a>{/capture}{include file="customer/main/bullet.tpl" content=$smarty.capture.bullet catmenu=true}
{/if}
{/foreach}
{else}
{foreach from=$subcategories item=c}
<a href="home.php?cat={$c.categoryid}" class="VertMenuCatItems">{$c.category}</a><br />
{/foreach}
{/if}
{/if}
<br />
<form method="POST" action="/cgi-bin/redirect.cgi">
<select name="url">
<option value="" selected="selected">Browse Manufacturers...</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=84">Accu-Fitness
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=114">ALRI
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=102">Amino Vital
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=117">Anabolic Resources
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=116">Anabolic Xtreme
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=108">ANSI
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=99">APEX
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=39">AST Sports Science
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=106">AXIS Labs
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=72">Balance Bars


<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=50">Bill Grant Nutrition
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=92">Bio Pharm
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=41">Bodybuilding Chemicals
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=58">Body FX
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=135">Bodywell Nutrition
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=146">BOSS Workout Supplies
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=2">BSN
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=133">Cardio Fire
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=36">Champion Nutrition
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=70">Chef Jay's
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=64">Clif Bar
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=112">CNS
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=121">Controlled Labs
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=6">Cyence
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=24">Cytodyne Technologies
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=139">Cytogenics
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=66">Cytosport
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=95">Delmar Labs
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=54">Detour Bars
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=137">Drinks that Work Inc
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=1">EAS
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=56">Eclipse Sport Supplements
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=40">Elite Delivery Technologies
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=65">Ergopharm</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=103">EST</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=37">Fitness Enterprises</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=11">Fizogen</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=122">Flexsports International</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=118">Gamma Enterprises</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=27">Gaspari Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=76">Gatorade</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=111">German American Tech</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=97">Gold's Water</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=144">Hampshire Labs</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=87">Health From The Sun</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=59">Healthy N' Fit</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=45">Hi-Tech Pharmaceuticals</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=46">Himalaya USA</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=69">Human Development</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=141">Iceman Rx</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=115">IFORCE</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=132">Inner Armour</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=68">Innovative Delivery Sys</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=105">INSTONE</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=77">Iovate</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=49">ISS</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=86">Jan Tana</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=104">Kilo Sports</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=83">Labrada Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=107">LBI Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=94">LG Science</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=25">Man Sports Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=26">Maximum Human</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=98">Maxoderm</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=82">Medical Research Institute</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=130">MEDPORT</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=73">Met-Rx</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=28">Molecular Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=124">Monster</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=156">MRI</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=20">Muscle Asylum Project</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=93">Muscle Foods</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=142">Muscle Fuel</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=4">Muscle Tech</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=48">National Health</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=62">Natural Source Products</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=33">Nature's Best</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=123">Nature's Select</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=43">Nature's Way</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=53">Next Proteins</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=63">Nutrabolics</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=13">Nutrex</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=67">NVE Pharmaceuticals</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=120">Palo Alto Labs</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=136">Panthera Pharmaceuticals</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=127">Poland Springs</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=109">Power Crunch</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=81">Power Fitness</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=96">Powerbutter</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=74">Powerfood</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=101">Premeir Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=125">Primaforce</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=85">Pro Lab Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=55">Pro Tan</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=51">Promax Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=110">Protos</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=113">PVL</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=140">RecoveryX</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=145">Reeves Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=57">RTO Sportsgear</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=30">San Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=47">Schiff</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=128">Science Foods</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=126">Scivations</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=78">Six Star</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=89">SNAC Systems</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=52">Sports One</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=100">Strength Systems USA</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=32">Super Spectrum</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=80">Syntrax innovations</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=29">THE BEAST Sports Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=138">The Shaker Cup Company</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=42">Thermolife</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=155">The Shaker Cup Company</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=61">Tiger's Milk</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=119">Turbo Shaker</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=35">Twin Lab</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=90">Udo's Oils</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=88">Ultra Lab</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=71">Universal Nutrition System</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=143">USP Labs</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=34">VHT</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=17">Vital Pharmaceuticals</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=44">Vitol</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=19">Vyotech</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=38">Weider Health &amp; Fitness</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=23">Worldwide Sports Nutrition</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=60">Zoller Labs</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=129">Zone Perfect</option>
<option value="http://fitnessopus.com/xcart/manufacturers.php?manufacturerid=131">Zydot</option>
</select>
<br />
<br />
<input type=submit name=submit value="Submit">
</form>

<br />
<br />

<br />
<a href="http://www.google.com" class="VertMenuCatItems">&nbsp;-&nbsp;Training Videos</a><br/><br />

<a href="http://www.thewindowfilmspecialist.com/index_hhr.html" class="VertMenuCatItems">&nbsp;-&nbsp;Links</a><br/>
</td>
</tr>
<tr>
<td valign="bottom">

<table width="100%" cellpadding="14" cellspacing="0" align="center">
<tr>
<td>
{if $js_enabled}
<a href="{$js_update_link|amp}" class="SmallNote">{$lng.txt_javascript_disabled}</a>
{else}
<a href="{$js_update_link|amp}" class="SmallNote">{$lng.txt_javascript_enabled}</a>
{/if}
</td>
</tr>
</table>

</td>
</tr>
</table>
{/capture}
{ include file="menu.tpl" dingbats="dingbats_categorie.gif" menu_content=$smarty.capture.menu cellpadding=$fc_cellpadding style="Categories"}

I'm VERY sorry for the size of this post, but I wanted to be thorough... Hopefully, as I learn more about Perl I'll become a more active member of these forums. Thank you in advance, guys!


rcrx3


(This post was edited by rcrx3 on Jan 5, 2009, 6:15 PM)


KevinR
Veteran


Jan 5, 2009, 9:20 PM

Post #2 of 17 (2300 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

Without looking over what you posted too closely, this looks wrong:


Code
print <<EOF;  
Content-type: text/html
Location: $array{'url'}
}
print "Content-type: text/html\n\n";
}
EOF


It probably should be:


Code
print "Location: $array{'url'}\n\n";


Assumes $array{'url'} is a full url, like:

http://www.example.com
-------------------------------------------------


FishMonger
Veteran / Moderator

Jan 5, 2009, 9:21 PM

Post #3 of 17 (2299 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

The Perl script is very poorly written, but before look at fixing it, have you looked at the error message in the web server error log?

Also, the way you're coding the values of the drop-down and in its processing in the perl script will allow the form to be hijacked and redirect to any url.


rcrx3
Novice

Jan 5, 2009, 10:14 PM

Post #4 of 17 (2295 views)
Re: [FishMonger] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

I have tried to talk to the host to get the server information, but they're being uncooperative. Actually, that (poorly written) script is just one of several online that I've tried, all with the same error.

I tried the above method, to no avail... also, this script is working: http://www.fitnessopus.com/helloworld.pl . Is there a piece of free code that I can use to make this work?

Thanks again for the help, it's VERY much appreciated.


FishMonger
Veteran / Moderator

Jan 5, 2009, 10:28 PM

Post #5 of 17 (2292 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

As a starting point, here's an improved version where I assume the drop-down is corrected accordingly and the redirects are all in the same base url as they are in your post.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI;

my $cgi = CGI->new;
my $id = $cgi->param('id');
my $baseurl = 'http://fitnessopus.com';
my $script = 'xcart/manufacturers.php';
my %manufacture = (
84 => 'Accu-Fitness',
114 => 'ALRI',
102 => 'Amino Vital',
# etc,
# etc,
);

exists $manufacture{$id} ? $cgi->redirect("$baseurl/$script?manufacturerid=$id")
: $cgi->redirect("$baseurl/error.html");



(This post was edited by FishMonger on Jan 5, 2009, 10:29 PM)


FishMonger
Veteran / Moderator

Jan 5, 2009, 10:40 PM

Post #6 of 17 (2289 views)
Re: [FishMonger] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

Oops, a slight syntax error, I forgot to print the redirect.

Also, you can use the CGI::Carp module to direct the error messages to the browser. However, that should be removed after the script is tested and goes into production.



Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $cgi = CGI->new;
my $id = $cgi->param('id');
my $baseurl = 'http://fitnessopus.com';
my $script = 'xcart/manufacturers.php';
my %manufacture = (
84 => 'Accu-Fitness',
114 => 'ALRI',
102 => 'Amino Vital',
# etc,
# etc,
);

exists $manufacture{$id} ? print $cgi->redirect("$baseurl/$script?manufacturerid=$id")
: print $cgi->redirect("$baseurl/error.html");



rcrx3
Novice

Jan 6, 2009, 7:37 AM

Post #7 of 17 (2281 views)
Re: [FishMonger] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

Ah, ok -- so the reason it could have been hijacked is that there was not a list of acceptable redirects or referrers in the .pl file ?


Then basically, I'll just need to leave the action of the embedded html form alone (/cgi-bin/redirect.pl) and modify the URLs how?



Code
<option value="$baseurl/$script?manufacturerid=84">Accu-Fitness


I really have to learn more about Perl....


Also, FishMonger - in the line " my %manufacture = ( " -- should this be "my %manufacturer = ( " ?

I only ask becuase I see it written as "manufacture" 2 times, and "manufacturer" once.


Thank you guys, this is helping a lot!


rcrx3
Novice

Jan 6, 2009, 7:56 AM

Post #8 of 17 (2278 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

OK so I've been experimenting... when I tried the above code, it said that "error.html cannot be found on this server".

I played around with it:


Code
#!/usr/bin/perl  

use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $cgi = CGI->new;
my $id = $cgi->param('id');
my $baseurl = 'http://fitnessopus.com';
my $script = 'xcart/manufacturers.php';
my %manufacturer = (
84 => 'Accu-Fitness',
114 => 'ALRI',
102 => 'Amino Vital',
117 => 'Anabolic Resources',
# etc,
);

exists $manufacturer$id ? print $cgi->redirect("$baseurl/$script?manufacturerid=$id")
: print $cgi->redirect("$baseurl/error.html");



Also, I changed my URL to this:


Code
<option value="$manufacturer{$84}">TESTING 123



And it returned this message:

"
Software error:

Global symbol "$manufacturer" requires explicit package name at /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl line 20.
syntax error at /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl line 20, near "$manufacturer$id "
Execution of /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl aborted due to compilation errors.

For help, please send mail to the webmaster (or webmaster), giving this error message and the time and date of the error."


Also, I removed a curly bracket on line 20 from the right of "exists $manufacturer$id " because I had an earlier error message saying this (in addition to the error above): " Unmatched right curly bracket at /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl line 20, at end of line
"


(This post was edited by rcrx3 on Jan 6, 2009, 7:58 AM)


FishMonger
Veteran / Moderator

Jan 6, 2009, 7:58 AM

Post #9 of 17 (2277 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post


In Reply To
Ah, ok -- so the reason it could have been hijacked is that there was not a list of acceptable redirects or referrers in the .pl file ?

Correct


In Reply To
Then basically, I'll just need to leave the action of the embedded html form alone (/cgi-bin/redirect.pl)

Yes, the action attribute will remain the same.


In Reply To
and modify the URLs how?



Code
<option value="$baseurl/$script?manufacturerid=84">Accu-Fitness



Code
<select name="id"> 
<option value="" selected="selected">Browse Manufacturers...</option>
<option value="84">Accu-Fitness</option>
<option value="114">ALRI</option>



In Reply To
Also, FishMonger - in the line " my %manufacture = ( " -- should this be "my %manufacturer = ( " ?

I only ask becuase I see it written as "manufacture" 2 times, and "manufacturer" once.


It could go either way but to stay consistent, it might be best to use "manufacturer".


rcrx3
Novice

Jan 6, 2009, 8:00 AM

Post #10 of 17 (2275 views)
Re: [FishMonger] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

excellent! I'll try right now; and I see now what you mean about the html code. Thanks for clarifying


rcrx3
Novice

Jan 6, 2009, 8:04 AM

Post #11 of 17 (2274 views)
Re: [FishMonger] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

I returned the script to your original one (thank you for that, by the way), and this is the error it's returning:

Software error:

Global symbol "$manufacturer" requires explicit package name at /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl line 20.
syntax error at /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl line 20, near "$manufacturer$id"
Unmatched right curly bracket at /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl line 20, at end of line
Execution of /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl aborted due to compilation errors.

For help, please send mail to the webmaster (or webmaster), giving this error message and the time and date of the error.


KevinR
Veteran


Jan 6, 2009, 9:11 AM

Post #12 of 17 (2268 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

In the code Fish posted earlier, this varible needs to be fixed:


Code
exists $manufacturer$id


should be:


Code
exists $manufacturer{$id}

-------------------------------------------------


rcrx3
Novice

Jan 6, 2009, 2:01 PM

Post #13 of 17 (2263 views)
Re: [KevinR] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

That was it! Here is the completed code for anyone that looks this thread up:


Code
#!/usr/bin/perl  

use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $cgi = CGI->new;
my $id = $cgi->param('id');
my $baseurl = 'http://fitnessopus.com';
my $script = 'xcart/manufacturers.php';
my %manufacture = (
84 => 'Accu-Fitness',
114 => 'ALRI',
102 => 'Amino Vital',
117 => 'Anabolic Resources',
# etc,
);

exists $manufacturer$id} ? print $cgi->redirect("$baseurl/$script?manufacturerid=$id")
: print $cgi->redirect("$baseurl/error.html");



Thanks VERY much for all the help, FishMonger and KevinR - if you guys ever need any graphic arts support, let me know and I will assist :)


rcrx3
Novice

Jan 6, 2009, 2:53 PM

Post #14 of 17 (2260 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

ah... I thought I was done, but now I'm getting this error? After this script was working, I used the same syntax to write out the whole list -- here is what I entered:



Code
 
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;

my $cgi = CGI->new;
my $id = $cgi->param('id');
my $baseurl = 'http://fitnessopus.com';
my $script = 'xcart/manufacturers.php';
my %manufacturer = (
84 => 'Accu-Fitness',
114 => 'ALRI',
102 => 'Amino Vital',
117 => 'Anabolic Resources',
84 => 'Accu-Fitness',
114 => 'ALRI',
102 => 'Amino Vital',
117 => 'Anabolic Resources',
116 => 'Anabolic Xtreme',
108 => 'ANSI',
99 => 'APEX',
39 => 'AST Sports Science',
106 => 'AXIS Labs',
72 => 'Balance Bars',
50 => 'Bill Grant Nutrition',
92 => 'Bio Pharm',
41 => 'Bodybuilding Chemicals',
58 => 'Body FX',
135 => 'Bodywell Nutrition',
146 => 'BOSS Workout Supplies',
2 => 'BSN',
133 => 'Cardio Fire',
36 => 'Champion Nutrition',
70 => 'Chef Jays',
64 => 'Clif Bar',
112 => 'CNS',
121 => 'Controlled Labs',
6 => 'Cyence',
24 => 'Cytodyne Technologies',
139 => 'Cytogenics',
66 => 'Cytosport',
95 => 'Delmar Labs',
54 => 'Detour Bars',
137 => 'Drinks that Work Inc',
1 => 'EAS',
56 => 'Eclipse Sport Supplements',
40 => 'Elite Delivery Technologies',
65 => 'Ergopharm',
103 => 'EST',
37 => 'Fitness Enterprises',
11 => 'Fizogen',
122 => 'Flexsports International',
118 => 'Gamma Enterprises',
27 => 'Gaspari Nutrition',
76 => 'Gatorade',
111 => 'German American Tech',
97 => 'Golds Water',
144 => 'Hampshire Labs',
87 => 'Health From The Sun',
59 => 'Healthy N Fit',
45 => 'Hi-Tech Pharmaceuticals',
46 => 'Himalaya USA',
69 => 'Human Development',
141 => 'Iceman Rx',
115 => 'IFORCE',
132 => 'Inner Armour',
68 => 'Innovative Delivery Sys',
105 => 'INSTONE',
77 => 'Iovate',
49 => 'ISS',
86 => 'Jan Tana',
104 => 'Kilo Sports',
83 => 'Labrada Nutrition',
107 => 'LBI Nutrition',
94 => 'LG Science',
25 => 'Man Sports Nutrition',
26 => 'Maximum Human',
98 => 'Maxoderm',
82 => 'Medical Research Institute',
130 => 'MEDPORT',
73 => 'Met-Rx',
28 => 'Molecular Nutrition',
124 => 'Monster',
156 => 'MRI',
20 => 'Muscle Asylum Project',
93 => 'Muscle Foods',
142 => 'Muscle Fuel',
4 => 'Muscle Tech',
48 => 'National Health',
62 => 'Natural Source Products',
33 => 'Nature's Best',
123 => 'Nature's Select',
43 => 'Nature's Way',
53 => 'Next Proteins',
63 => 'Nutrabolics',
13 => 'Nutrex',
67 => 'NVE Pharmaceuticals',
120 => 'Palo Alto Labs',
136 => 'Panthera Pharmaceuticals',
127 => 'Poland Springs',
109 => 'Power Crunch',
81 => 'Power Fitness',
96 => 'Powerbutter',
74 => 'Powerfood',
101 => 'Premeir Nutrition',
125 => 'Primaforce',
85 => 'Pro Lab Nutrition',
55 => 'Pro Tan',
51 => 'Promax Nutrition',
110 => 'Protos',
113 => 'PVL',
140 => 'RecoveryX',
145 => 'Reeves Nutrition',
57 => 'RTO Sportsgear',
30 => 'San Nutrition',
47 => 'Schiff',
128 => 'Science Foods',
126 => 'Scivations',
78 => 'Six Star',
89 => 'SNAC Systems',
52 => 'Sports One',
100 => 'Strength Systems USA',
32 => 'Super Spectrum',
80 => 'Syntrax Innovations',
29 => 'THE BEAST Sports Nutrition',
138 => 'The Shaker Cup Company',
42 => 'Thermolife',
155 => 'The Shaker Cup Company',
61 => 'Tiger's Milk',
119 => 'Turbo Shaker',
35 => 'Twin Lab',
90 => 'Udo's Oils',
88 => 'Ultra Lab',
71 => 'Universal Nutrition System',
143 => 'USP Labs',
34 => 'VHT',
17 => 'Vital Pharmaceuticals',
44 => 'Vitol',
19 => 'Vyotech',
38 => 'Weider Health And Fitness',
23 => 'Worldwide Sports Nutrition',
60 => 'Zoller Labs',
129 => 'Zone Perfect',
131 => 'Zydot',
);

exists $manufacturer{$id} ? print $cgi->redirect("$baseurl/$script?manufacturerid=$id")
: print $cgi->redirect("$baseurl/error.html");


Software error:

Substitution replacement not terminated at /services/webpages/f/i/fitnessopus.com/cgi-bin/redirect.pl line 127.


KevinR
Veteran


Jan 6, 2009, 3:14 PM

Post #15 of 17 (2256 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

In the hash, any lines like this:


Code
                  61 => 'Tiger's Milk',


need to be:


Code
                  61 => 'Tiger\'s Milk',


You can't put single-quotes in a single-quoted string without escaping them or using a quoting operator. Just add the backslash as shown above to escape them.
-------------------------------------------------


(This post was edited by KevinR on Jan 6, 2009, 3:15 PM)


FishMonger
Veteran / Moderator

Jan 6, 2009, 3:21 PM

Post #16 of 17 (2254 views)
Re: [rcrx3] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

The problem is originating from line 93

Code
33 => 'Nature's Best',

Since we're using single quotes to delimitate the string, you need to escape the single quote within the string or use one of the other quoting methods.

Any of these are valid

33 => 'Nature\'s Best',
33 => "Nature's Best",
33 => q(Nature's Best),
33 => qq(Nature's Best),

You have the same issue on lines 94 & 95 and possibly others.


rcrx3
Novice

Jan 6, 2009, 3:27 PM

Post #17 of 17 (2252 views)
Re: [FishMonger] Probably an easy one... redirect.pl server error, can't use script! [In reply to] Can't Post

You are both exactly right. Thanks again, guys.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives