Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$ENV{'QUERY_STRING'}

Status
Not open for further replies.

lonelyplanet

Technical User
Apr 4, 2004
1
HK
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 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= Guestbook</b></td></tr>
<form method=post action=<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="<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=</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 ' 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;
}
}
 
Probably something in the transport. Stop doing your own CGI translations and use CGI.pm, i'd bet the problem disappears.

People *think* HTTP is super simple and write their own translations but there are actually a lot of wacky little crevices that will break like yours did here.

 
Are there any free Perl/CGI script sites that write good code? Clean style, proper use of modules, some semblance of default security? Maybe I'm being overly critical, but code I see that comes from these things tend to be just barely above what the average "my first program!"-er produces.

Different browsers cache pages differently, and create all kinds of little problems when debugging.

________________________________________
Andrew - Perl Monkey
 
Usually freely available code sites are terrible. Most of the good coders are off actually writing good code for a living.

Ok, sorry, generalization :) But i agree, its pretty amatuer hour out there.
 
lonelyplanet,

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

Using the method "post" sends form data to STDIN so the
query string is always empty.

HTH
 
Yet another reason to use CGI.pm rather then rolling your own parsing routine.....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top