Lunarpages Web Hosting Forum

Author Topic: Getting an Error 500/"Premature end of script headers" error when accessing %ENV  (Read 3887 times)

Offline acrosser

  • Newbie
  • *
  • Posts: 1
I have a Perl script running in /tony5/cgi-bin/ -- it's called rand.pl.

If I just use "print ..." statements the Perl script is executed just fine.

But when I try to access the POST content using the %ENV hash, I get an Error 500.

This is the error I get in the Server Error Log:

"[Sun Apr 13 19:33:04 2008] [error] [client 24.21.223.141] Premature end of script headers: /home/space28/public_html/tony5/cgi-bin/rand.pl"

Here is my script, rand.pl (between the ------ lines):
-----------------------------
#!/usr/bin/perl
print "content-type: text/html \n\n";
print "<html><body>\n<br />\n";
print "Testing...";
print $ENV{'REQUEST_METHOD'};
print "123...";
print "<br />\n</body></html>";
-----------------------------

If I #COMMENT OUT the line "print $ENV{'REQUEST_METHOD'};" then the script runs just fine and prints out a few lines. But if I leave that line in then I get the "Error 500/Premature end of script headers" error.

In my HTML code, here is the <FORM> tag that is calling the script:

<form action="/cgi-bin/rand.pl" name="randForm" method="POST">

Any ideas? Is there another way to access the GET/POST data besides the %ENV hash?


Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6404
Well, my Learning Perl book (O'Reilly) shows the following for processing information from a form:

Code: [Select]
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);

# start of output page
print header, start_html("Page Title"), h1("Big Heading");

if (param()) {
  # something was passed in
  my $field1 = param("field1");  # etc
}

Maybe that will be a start... %ENV is for environmental variables such as $PATH, which may not even be available in a server (Web) environment.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline bent

  • Newbie
  • *
  • Posts: 2
I'm attempting a simple open and close. I am getting error: Premature end of script headers. The permissions on both the file and the script are 755. I uploaded both using type of ASCII.   Yet, I get the error. What am I missing?

Thanks!


#!/usr/bin/perl
$myfile = "home/bentin2/public_html/dqfiles/bbtfile.txt";
open (DATAF, "$myfile");
close(DATAF);

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6404
Change

open (DATAF,"$myfile");

to

open (DATAF, $myfile);

and see if anything improves. This is Perl, not PHP.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline bent

  • Newbie
  • *
  • Posts: 2
Thanks for the response. Good catch.