outputting the results of something.pl

J

jim jowski

I've written an html form that will pass three values to a script called
'something.pl' which lives in my cgi-bin directory. When something.pl
is executed; I get the following error message:

[Sun Apr 17 08:24:37 2005] [error] [client 127.0.0.1] malformed header
from script. Bad header=<html><head><title>the title</:
/var/www/cgi-bin/something.pl

'something.pl' is nothing more than:

#!/usr/bin/perl

$dollar0 = @ARGV[0];
$dollar1 = @ARGV[1];
$dollar2 = @ARGV[2];

print "<html><head><title>the title</title></head>";
print "<body><p>dollar0 = $dollar0\n";
print "<p>\tdollar1 = $dollar1\n";
print "<p>\t\tdollar2 = $dollar2\n";
print "</body></html>";

and the html form that calls 'something.pl' is:

<html><head><title>input</title></head>
<body><form method="post" action="/cgi-bin/something.pl">
<P>value 0: <input type="text" name="v0" size=10></p>
<P>value 1: <input type="text" name="v1" size=10></p>
<P>value 2: <input type="text" name="v2" size=10></p>
<P><input type="submit" name="submit" value="calculate"></P>
</form>
</body>
</html>

I know that I can do all this with PHP but I have too much time invested
in perl code that I can clone to migrate. Once I have this simple
output problem solved, I can hopefully do the rest of the project this week.

Thanks,
Jim
 
B

Brian Wakem

jim said:
I've written an html form that will pass three values to a script called
'something.pl' which lives in my cgi-bin directory. When something.pl
is executed; I get the following error message:

[Sun Apr 17 08:24:37 2005] [error] [client 127.0.0.1] malformed header
from script. Bad header=<html><head><title>the title</:
/var/www/cgi-bin/something.pl


You need to print a content type header first.

print "Content-type: text/html\n\n";
 
T

Tad McClellan

jim jowski said:
I get the following error message:

[Sun Apr 17 08:24:37 2005] [error] [client 127.0.0.1] malformed header
from script. Bad header=<html><head><title>the title</:
/var/www/cgi-bin/something.pl
#!/usr/bin/perl

$dollar0 = @ARGV[0];
^
^

You should always enable warnings when developing Perl code!

CGI programs do not normally get command line arguments.

What info are you expected to get into $dollar0?

You should use the CGI.pm module to get access to the form values.



Output a proper header before the body:

print "Content-Type: text/html\n\n";

The CGI.pm module can write a proper header for you too.

print "<html><head><title>the title</title></head>";


That is not a proper header, so you get a message about an
improper header.

I know that I can do all this with PHP


So you already know how to print a proper header in PHP?

Once I have this simple
output problem solved,


But you don't know how to print a proper header in Perl?

You use Perl's print() function to make output.



Have you seen Perl's Frequently Asked Questions about CGI programming?

perldoc -q CGI

Where can I learn about CGI or Web programming in Perl?

What is the correct form of response from a CGI script?

My CGI script runs from the command line but not the browser. (500
Server Error)

How can I get better error messages from a CGI program?

How do I make sure users can't enter values into a form that cause my
CGI script to do bad things?

How do I decode a CGI form?
 
J

John

Maybe you need to backquote or escape-out the slashes in your literal

instead of:

<title>the title</title>

maybe:

<title>the title<\/title>
 
J

jim jowski

Tad said:
I get the following error message:

[Sun Apr 17 08:24:37 2005] [error] [client 127.0.0.1] malformed header
from script. Bad header=<html><head><title>the title</:
/var/www/cgi-bin/something.pl

#!/usr/bin/perl

$dollar0 = @ARGV[0];

^
^

You should always enable warnings when developing Perl code!

CGI programs do not normally get command line arguments.

What info are you expected to get into $dollar0?

You should use the CGI.pm module to get access to the form values.



Output a proper header before the body:

print "Content-Type: text/html\n\n";

The CGI.pm module can write a proper header for you too.


print "<html><head><title>the title</title></head>";



That is not a proper header, so you get a message about an
improper header.


I know that I can do all this with PHP



So you already know how to print a proper header in PHP?


Once I have this simple
output problem solved,



But you don't know how to print a proper header in Perl?

You use Perl's print() function to make output.



Have you seen Perl's Frequently Asked Questions about CGI programming?

perldoc -q CGI

Where can I learn about CGI or Web programming in Perl?

What is the correct form of response from a CGI script?

My CGI script runs from the command line but not the browser. (500
Server Error)

How can I get better error messages from a CGI program?

How do I make sure users can't enter values into a form that cause my
CGI script to do bad things?

How do I decode a CGI form?

I'll check "perldoc -q CGI" and try to get smart. :^)

Actually, the problem is one of making the form available and passing
the POSTings to a script that hides its source code. After I initially
posted the question, I found the FAQ reference to:

print "Content-Type: text/html\n\n";

and was able to output an HTML page but no $dollar0 - $dollar2 inputs.
At least I'm heading down the right path regarding getting the output
but now passing the input is the problem.

Thanks again,
Jim
 
J

jim jowski

jim said:
I've written an html form that will pass three values to a script called
'something.pl' which lives in my cgi-bin directory. When something.pl
is executed; I get the following error message:

[Sun Apr 17 08:24:37 2005] [error] [client 127.0.0.1] malformed header
from script. Bad header=<html><head><title>the title</:
/var/www/cgi-bin/something.pl

'something.pl' is nothing more than:

#!/usr/bin/perl

$dollar0 = @ARGV[0];
$dollar1 = @ARGV[1];
$dollar2 = @ARGV[2];

print "<html><head><title>the title</title></head>";
print "<body><p>dollar0 = $dollar0\n";
print "<p>\tdollar1 = $dollar1\n";
print "<p>\t\tdollar2 = $dollar2\n";
print "</body></html>";

and the html form that calls 'something.pl' is:

<html><head><title>input</title></head>
<body><form method="post" action="/cgi-bin/something.pl">
<P>value 0: <input type="text" name="v0" size=10></p>
<P>value 1: <input type="text" name="v1" size=10></p>
<P>value 2: <input type="text" name="v2" size=10></p>
<P><input type="submit" name="submit" value="calculate"></P>
</form>
</body>
</html>

I know that I can do all this with PHP but I have too much time invested
in perl code that I can clone to migrate. Once I have this simple
output problem solved, I can hopefully do the rest of the project this
week.

Thanks,
Jim

I was able to get the output of 'something.pl' to display by changing it to:

#!/usr/bin/perl

use CGI;
$query = new CGI;
@names = $query->param; #the names of the passed parameters
$dollar0 = $query->param('v0');
$dollar1 = $query->param('v1');
$dollar2 = $query->param('v2');

print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>the TITLE</TITLE></HEAD>\n\n<BODY>";
print "<p>dollar0 = $dollar0\n";
print "<p>\tdollar1 = $dollar1\n";
print "<p>\t\tdollar2 = $dollar2\n";
print "</BODY></HTML>";

This brought in the passed parameter values by using $query-> and the
"Content-..." line with two newlines made the header legal. (Good thing
too because the programming police were on their way...)

Thanks again to all, especially Tad McClellan, for the gentle guidance
in the right direction. Maybe these snippets will be useful to others
"when" the same question arises.

Jim
 
J

John W. Krahn

John said:
Maybe you need to backquote or escape-out the slashes in your literal

instead of:

<title>the title</title>

maybe:

<title>the title<\/title>

He would if he was doing:

print qq/<title>the title<\/title>/;

Instead of:

print "<title>the title</title>";

Slashes are not special in double quoted strings.



John
 
T

Tad McClellan

jim jowski said:
Tad said:
$dollar0 = @ARGV[0];
CGI programs do not normally get command line arguments.
You should use the CGI.pm module to get access to the form values.

Actually, the problem is one of making the form available

At least I'm heading down the right path regarding getting the output
but now passing the input is the problem.


CGI programs do not normally get command line arguments.

You should use the CGI.pm module to get access to the form values.
 
A

Alan J. Flavell

On Sun, 17 Apr 2005, jim jowski wrote:

[excessive quotage snipped]
I was able to get the output of 'something.pl' to display by
changing it to:

#!/usr/bin/perl

A pity that you offer indirect thanks to Tad, while apparently
ignoring his oft-repeated advice...[1]
use CGI;
$query = new CGI;
wibble

@names = $query->param; #the names of the passed parameters
$dollar0 = $query->param('v0');
$dollar1 = $query->param('v1');
$dollar2 = $query->param('v2');

print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>the TITLE</TITLE></HEAD>\n\n<BODY>";

Talk about getting a dog and barking for yourself...

CGI.pm is happy to generate this correctly for you (in xhtml or html
flavours at your option).

Omitting the appropriate charset specification from the Content-type:
header can have some unpleasant consequences when handling forms
input. It's also a security exposure according to CA-2000-02 (a
rather complex bag of stuff, but the advice in this regard was clear
enough).
"Content-..." line with two newlines made the header legal.

Well, yes, as far as *that* went.
Thanks again to all, especially Tad McClellan, for the gentle
guidance in the right direction.

[1] But you still didn't take the advice that's churned out here
countless times a day, to ask Perl for all the help it can give.
Which means using strict, and (at least during development) using
warnings. And in the case of CGI one should make taint checking (-T)
one's default.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top