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!

Help Getting Started... again

Status
Not open for further replies.

mtorbin

Technical User
Nov 5, 2002
369
US
Hey all,

I've been away from this for about two years, so I really appreciate your patience and understanding.

I'm trying to determine whether or not my Apache is setup correctly to run cgi scripts. I have a test cgi script which looks like the following:

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';

my $animal;
$animal = param('animal');

lprint "Content-type" text/html\n\n";
lprint "Yes this works!\n\n";
lprint "You ROCK man!";

Now, I know there's some unnecessary stuff in there, but to my knowledge, nothing in there should be giving me any trouble if it just sits there. Unfortunately, I'm getting the following in the error_log:

Premature end of script headers

Frankly, I can't quite remember what this means so I'm throwing myself at your mercy (until I catch up to where I was). Any advice?

- MT
 
Your headers are printing incorrectly

lprint "Content-type" text/html\n\n";

try

print $query->header;

instead.

And I have never seen or used lprint, I'd advise using the norman 'print' statement.
 
Thanks for the advice:

I made the changes, but I seem to be getting the same results. Here's what I currently have:


#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';

print $query->header;
print "Yes this works!\n\n";
print "You ROCK man!";

Question: Would I get the "premature end..." error if my link to Perl was incorrect?

- MT
 
I'm also now getting the following errors when I changed the link to Perl:

[Mon Dec 01 12:58:19 2003] [error] [client ipAddress] Global symbol "$query" requires explicit package name at /[location]/cgi-bin/cgitest.cgi line 6.
[Mon Dec 01 12:58:19 2003] [error] [client ipAddress] Execution of /[ocation]/cgi-bin/cgitest.cgi aborted due to compilation errors.

I think I'm on the right track but I'm missing a few things.

- MT
 
You're using the strict pragma so you have to declare your variables. You also have to create an instance of CGI. Also, open and close the body tag by calling start_html and end_html. Here's what your code should look like:
Code:
#!/your/path/to/perl
use strict;
use CGI ':standard';

my $query = new CGI;
print $query->header;
print $query->start_html;
print "Yes this works!\n\n";
print "You ROCK man!";
print $query->end_html;

And don't forget to read the manual:


Kevin
A+, Network+, MCP
 
Thanks for the link to that maual. That's going to be the most valuable thing to me throughout this process!

I actually got it to work, so now I'm on my way... I hope.

- MT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top