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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Premature end of script headers

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Whenever I run a cgi script I get an Internal server error and my error log say premature end of script header. I don't know what caused this or how to fix it.
If anyone could help I would appreciate it.
thanks,
mike
 
Make sure your script sends "Content-type: text/html" and 2 newlines before anything else. e.g. in perl:

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

If it already does, then the script probably has an error occuring before the header is sent. Try running your perl script on the command line through telnet to see where the error is. C:\DOS:>
C:\DOS:>RUN
RUN DOS RUN!!
 
Hi,

This normally just means some kind of syntax error in the script or even that the script handler can't spawn the perl (or whatever) process because the path next to the 'shebang' (#!) on the first line is wrong . For example on linux/unix it would have something like :

#!/usr/bin/perl
##
## printenv -- demo CGI program which just prints its environment
##
print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}


and the M$ equivalent might be

#!c:/perl/bin/perl.exe
##
## printenv -- demo CGI program which just prints its environment
##
print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}


In other words - check your path ...

Also, on linux/unix you may have forgotton to make the script executable ...

# cd /var/# chmod +x myscript.cgi

Hope this helps
 
Hi,

Wullie's right on that but you need :

ScriptInterpreterSource registry

active in httpd.conf and its turned off by default.

Regards
 
Hi,

Maybe I phrased it confusingly... what I meant was that if you don't want to be bothered with the shebang on windows you can uncomment that line. The shebang then becomes irrelevant. I.e. :

#ScriptInterpreterSource registry

= the shebang path applies on windows as it does on unix - i.e. must be correct

ScriptInterpreterSource registry

= the shebang path doesn't matter on windows because it will use the info the the windows registry.


Cut 'n' pasted from win32 httpd.conf :

# However, Apache on Windows allows either the Unix behavior above, or can
# use the Registry to match files by extention. The command to execute
# a file of this type is retrieved from the registry by the same method as
# the Windows Explorer would use to handle double-clicking on a file.
# These script actions can be configured from the Windows Explorer View menu,
# 'Folder Options', and reviewing the 'File Types' tab. Clicking the Edit
# button allows you to modify the Actions, of which Apache 1.3 attempts to
# perform the 'Open' Action, and failing that it will try the shebang line.
# This behavior is subject to change in Apache release 2.0.
#
# Each mechanism has it's own specific security weaknesses, from the means
# to run a program you didn't intend the website owner to invoke, and the
# best method is a matter of great debate.
#
# To enable the this Windows specific behavior (and therefore -disable- the
# equivilant Unix behavior), uncomment the following directive:
#
#ScriptInterpreterSource registry
#


Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top