Solved

$ENV{'QUERY_STRING'}

Posted on 2004-04-04
4
3,570 Views
Last Modified: 2011-09-20
Hi,

Previously, I have written a guestbook homepage plus a backend cgi script for my friend. I modified the perl script written by creators from  http://www.thanks-cgi.com. The modified script worked normal in the old web hosting site (running under linux platform).

However, my friend recently told me that he wanted to move the created pages to a new web hosting company which used windows 2000 platform.

I found my script no longer worked. So I tried to check whether it's about file paths issues.

My simple guestbook html (file guestbook.htm) content is as follow:

<html><head><title>Wedding Guestbook</title></head>
<body bgcolor=eeeecc text=000000>

<table border=0>
<tr><td colspan=2><img src=http://www.something.com/images/led.gif><b>Wedding Guestbook</b></td></tr>
<form method=post action=http://www.something.com/cgi-bin/guestbook.cgi>
<input type=hidden name="job" value="add">
<tr><td>Your Name:</td><td><input type=text size=25 name="username">E-mail:<input type=text size=25 name="usermail"></td></tr>
<tr><td>Website (if any):</td><td><input type=text size=58 name="userurl" value="http://"></td></tr>
<tr><td valign=top>Message:</td><td><textarea name="says" wrap=hard rows="4" cols="57"></textarea></td></tr>
<tr><td colspan=2 align=center><input type=submit value="Submit"><input type=reset value="Reset"></td></tr>
<! modified part 'Submit' used instead of 'send', 'Reset' used instead of 'reset'>
</form>
</table>
<hr>

<!--begin-->


<center><a href=http://www.something.com/guestbook_manage.htm>CONTROL</a>
</body>
</html>

To help with debugging, I changed guestbook.cgi with test.cgi which has below content:

# e:/domains/AccountDomain/user/htdocs/cgi-bin

$new_number = 23;
print "Content-type: text/html\n\n";
print "I am OK!";
print "I am OK!";
print "I am OK!";
print $new_number;

As I clicked on "submit" button of guestbook.htm, I found test.cgi got executed and printed

I am OK!I am OK!I am OK!23

So I modified the script as follow:

# e:/domains/AccountDomain/user/htdocs/cgi-bin

$new_number = 23;
print "Content-type: text/html\n\n";
print "I am OK!";
print "I am OK!";
print "I am OK!";
print $new_number;
@querys = split(/&/, $ENV{'QUERY_STRING'});
foreach $query (@querys) {
  ($name, $value) = split(/=/, $query);
  $FORM{$name} = $value;
  print $name;
  print $value;    
}
print $ENV{'QUERY_STRING'};

This time only

I am OK!I am OK!I am OK!23 being printed and url shown in browser window was 'http://www.something.com/cgi-bin/test.cgi' no matter what I entered in the form.

I would like to ask why it nothing being received and it seemed even the value of $ENV{'QUERY_STRING'} was empty ?

:(

Remarks: Actually, the added code in test.cgi is the first few lines of code of my original .cgi which is

print "Content-type: text/html\n";
print "Pragma:no-cache\n\n";

&get_data;

#... other code skipped for illustration simplicity

sub get_data {
@querys = split(/&/, $ENV{'QUERY_STRING'});      
foreach $query (@querys) {                        
  ($name, $value) = split(/=/, $query);                  
  $FORM{$name} = $value;    
}

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);                        

foreach $pair (@pairs) {                        
   ($name, $value) = split(/=/, $pair);                  

   # Un-Webify plus signs and %-encoding
   $value =~ tr/+/ /;                                    
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;

   if ($allow_html != 1) {
      $value =~ s/<([^>]|\n)*>//g;
      $value =~ s/<([^>]|\n)*//g;
   }
   else {
      unless ($name eq 'says') {
         $value =~ s/<([^>]|\n)*>//g;
         $value =~ s/<([^>]|\n)*//g;
      }
   }
   $FORM{$name} = $value;
}
}
0
Comment
Question by:lonelyplanet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 10755033
The form is submiting with a POST not a GET

use CGI;
my $q = CGI->new;
%FORM=$q->Vars;

for( keys %FORM ){
    print "$_=$FORM{$_}<br>";
}
0
 
LVL 8

Expert Comment

by:davorg
ID: 10755529
In a POST request, the CGI parameters aren't in $ENV{QUERY_STRING}, you need to read them from STDIN.

As ozo points out this is a good reason to use CGI.pm. It handles both kinds of request and you don't even have to know what kind of request it is.

Dave...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question about @INC variable in perl 1 76
Awk Question 2 136
Control Number of Log Files -Perl 7 102
Internal Server Error on 1&1 Apache Server running PERL 3 98
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question