×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

basic problem I don't get!

basic problem I don't get!

basic problem I don't get!

(OP)
can anyone please tell me what is wrong with this script? I have staired at it for more than an hour and it looks like it sould work to me, but when I go to the page it will only direct me to the "one" page and not any of the other pages when I select "two" or "three"


#!/usr/bin/perl
 
#print "Content-type:text/html\n\n";
 
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair(@pairs)
{
  ($name,$value)=split(/=/,$pair);
  $value=~tr/+//;
  $value=~s/%([a-fA-f0-9][a-fA-f0-9])/pack("C",hex($1))/eg;
  $FORM{$get_page}=$value;
}
 
#require "cgi-lib.cgi";
#&ReadParse(*input);
#$uname= $input{'get_page'};
 
if ($get_page eq "one") {
  print "Location:http://127.0.0.1/under_construction.html\n\n";;
}
elsif ($get_page eq "two") {
  print "Location:http://127.0.0.1/help.html\n\n";;
}  
else {
  print "Location:http://127.0.0.1/server.html\n\n";;
}  

RE: basic problem I don't get!

two possible causes:
  you should predeclare %FORM outside of the foreach loop, or it will only be available inside of it (i probably wrong about the necessity of this one, but am used to stricter coding rules than normal cgi's).
  in the foreach loop, you should say '$FORM{$name} ...' instead of '$FORM{$get_page} ...'.  this is the spot that's probably the cause.  when it sets the value, it's setting it to the entry in %FORM keyed by the value of $get_page(which is nothing at this point), and NOT setting it to $get_page.  i'm not quite sure, because if this is the case, it would have always defaulted to case 'three', which you say it didn't.  in any case, i made the if conditions stricter as well to prevent that particular happenstance.  now, for the 'if' conditionals at the bottom, you'll need to say 'if ($FORM{get_page} eq 'one')'.
so, here's what the main part will look like:

read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
%FORM = ();
@pairs=split(/&/,$buffer);
foreach $pair(@pairs)
{
  ($name,$value)=split(/=/,$pair);
  $value=~tr/+//;
  $value=~s/%([a-fA-f0-9][a-fA-f0-9])/pack("C",hex($1))/eg;
  $FORM{$name}=$value;
}

if ($FORM{get_page} eq "one") {
  print "Location:http://127.0.0.1/under_construction.html\n\n";;
}
elsif ($FORM{get_page} eq "two") {
  print "Location:http://127.0.0.1/help.html\n\n";;
}
elsif ($FORM{get_page} eq "three") {
  print "Location:http://127.0.0.1/server.html\n\n";;
}

next time this happens, try using 'perl -w' and you'll get warning messages that may lead you to finding the problem.

"If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close