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!

Premature ending of script headers

Status
Not open for further replies.

programmerhead

Programmer
Sep 15, 2003
6
US
Can anyone tell me what "Premature ending of script headers" mean? I keep getting it in my error log with every script I am running. Here is what my script looks like:

#!/usr/bin/perl
use strict;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);


my $username = param('username');
my $password = param('password');
my ($breaker, $correct, $i, $name);


#THIS SECTION OF CODE IS RESPONSIBLE FOR OPENING THE FILE
print "Content-type: text/html\n\n";
print <<'opening';
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;<html xmlns=&quot;<head>
<meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; />
<title>Home of the Boom</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../base.css&quot; />
<script type=&quot;text/javascript&quot; languages=&quot;javascript&quot; src=&quot;../loadimages.js&quot;></script>
<style>A:hover {color: #000000}</style>
</head>
<body link=&quot;#3BAAFF&quot; vlink=&quot;#3BAAFF&quot; alink=&quot;#3BAAFF&quot;>
<center><img border=&quot;0&quot; src=&quot;../images/projectboom.gif&quot; align=&quot;center&quot; width=&quot;800&quot; height=&quot;75&quot; title=&quot;Home of the Boom&quot;></center>
<div align=&quot;center&quot;>
<center>
<table border=&quot;0&quot; width=&quot;700&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td width=&quot;33%&quot; colspan=&quot;3&quot; align=&quot;center&quot;>
<table border=&quot;0&quot; cellspacing=&quot;1&quot; cellpadding=&quot;0&quot;>
<tr height=&quot;40&quot;>
<td width=&quot;10&quot; valign=&quot;bottom&quot;><a href=&quot;../index.html&quot; onmouseover=&quot;document.home.src=tabhomdownon.src&quot;
onmouseout=&quot;document.home.src=tabhomdownoff.src&quot;>
<img border=&quot;0&quot; src=&quot;../images/tabhomdownoff.gif&quot; name=&quot;home&quot; width=&quot;90&quot; title=&quot;Home&quot;></a></td> <td width=&quot;10&quot; valign=&quot;bottom&quot;><a href=&quot;../index2.html&quot; onmouseover=&quot;document.members.src=tabmemdownon.src&quot;
onmouseout=&quot;document.members.src=tabmemdownoff.src&quot;>
<img border=&quot;0&quot; src=&quot;../images/tabmemdownoff.gif&quot; name=&quot;members&quot; width=&quot;90&quot; title=&quot;Members&quot;></a></td>
<td width=&quot;10&quot; valign=&quot;bottom&quot;><a href=&quot;../partyarchive.html&quot;
onmouseover=&quot;document.pictures.src=tabpicdownon.src&quot;
onmouseout=&quot;document.pictures.src=tabpicdownoff.src&quot;>
<img border=&quot;0&quot; src=&quot;../images/tabpicdownoff.gif&quot; name=&quot;pictures&quot; width=&quot;90&quot; height=&quot;35&quot; title=&quot;Pictures&quot;></a></td>
<td width=&quot;10&quot; valign=&quot;bottom&quot;><a href=&quot;../misc.html&quot; onmouseover=&quot;document.misc.src=tabmiscdownon.src&quot;
onmouseout=&quot;document.misc.src=tabmiscdownoff.src&quot;>
<img border=&quot;0&quot; src=&quot;../images/tabmiscdownoff.gif&quot; name=&quot;misc&quot; title=&quot;Misc.&quot;></a></td>
<td width=&quot;10&quot; valign=&quot;bottom&quot;><a href=&quot;../messageboard.html&quot; onmouseover=&quot;document.messageboard.src=tabmesdownon.src&quot;
onmouseout=&quot;document.messageboard.src=tabmesdownoff.src&quot;>
<img border=&quot;0&quot; src=&quot;../images/tabmesdownoff.gif&quot; name=&quot;messageboard&quot; title=&quot;Message Board&quot;></a></td>
</tr>
<tr>
<td colspan=&quot;5&quot;>
<hr noshade color=&quot;#0017C0&quot; size=&quot;3&quot;></td>
</tr>

</table>
</td>
</tr>
<tr>
<td width=&quot;33%&quot;></td>
<td width=&quot;33%&quot;></td>
<td width=&quot;34%&quot;></td>
</tr>
<tr>
<td width=&quot;33%&quot;></td>
<td width=&quot;33%&quot;></td>
<td width=&quot;34%&quot;></td>
</tr>
</table>
</center>
</div>
opening


#THIS SECTION OF CODE IS RESPONSIBLE FOR CHECKING THE USERNAME AND PASSWORD FOR AUTHENTICITY
open (LOG, &quot;< friends.txt&quot;) || Error('open','file');
flock (LOG, 2) || Error('lock','file');
my @gol = <LOG>;
close(LOG) || Error('close', 'file');
$i=0;
$breaker=0;
$correct=0;
until($breaker==1){
chop($gol[$i]);
chop($gol[$i]);
if($gol[$i] eq '()()()()'){
$breaker=1;
}
if($username eq $gol[$i]){
$breaker=1;
$i++;
chop($gol[$i]);
chop($gol[$i]);
if($password eq $gol[$i]){
$correct=1;
$i++;
chop($gol[$i]);
chop($gol[$i]);
$name=$gol[$i];
}
}
$i=$i+5;
}


#THIS SECTION OF CODE IS RESPONSIBLE FOR DISPLAYING THE FRIENDS OF BOOM MEMBERS OPTIONS PAGE
if($correct==1){
$password = crypt(1, $password);
print '<center>';
print '<br />';
print &quot;Hello $name, you are logged in as: $username\n&quot;;
print '<br /><br />';
print '<table border=0 cellspacing=1 cellpadding=0 width=350>';
print ' <tr>';
print ' <td bgcolor=&quot;#017EDE&quot; align=&quot;center&quot;>';
print ' <font size=6>Friend Of Booom Options:</font>';
print ' </td>';
print ' </tr>';
print ' <tr>';
print ' <td>';
print &quot; <a href=\&quot;exclusivepics.cgi?username=$username&password=$password\&quot;>Exclusive Picture Section</a>\n&quot;;
print ' </td>';
print ' </tr>';
print ' <tr>';
print ' <td>';
print &quot; <a href=\&quot;directory.cgi?username=$username&password=$password\&quot;>Member Directory</a>\n&quot;;
print ' </td>';
print ' </tr>';
print ' <tr>';
print ' <td>';
print &quot; <a href=\&quot;profile.cgi?username=$username&password=$password\&quot;>Edit Your Profile</a>\n&quot;;
print ' </td>';
print ' </tr>';
print '</table>';
print '<br /><br />';
}


#THIS SECTION OF CODE IS RESPONSIBLE FOR PRINTING THE ERROR MESSAGE
if($correct==0){
print '<center>';
print '<br /><br />Either the username or password you have entered is incorrect';
}


#THIS SECTION OF CODE IS RESPONSIBLE FOR ENDING THE HTML FILE
print &quot;</body></html>\n&quot;;
 
I think it's the way you're calling CGI. THis is what you have now use CGI ':standard';

Try this instead: use CGI qw:)standard);

There's always a better way. The fun is trying to find it!
 
&quot;Premature ending of script headers&quot;

When you request a static web page from a web server, the web server automatically builds a 'header' that precedes the content of the page. The info in the header is stuff about the response that the web server is sending back to the requesting application (a browser). That info is easily gathered for a static page.

However, when you request a page from a web server that is produced by a piece of CGI, the web server does NOT create a header. The web server can't possibly know the results of running the CGI code so web servers expect CGI applications to create/send their own headers.

In the event that a CGI has a syntax error or fails some dependency, the CGI will spit out an error, not a valid HTML header. So, if you are getting a 'Premature ending of script headers' error, then you probably have a syntax error. TVIMAN is probably correct.

There are a couple of tricks to debug your stuff. If you get a 'Premature ending of script headers' error, try doing a syntax check on the code from a command prompt.

Code:
prompt> perl -c your_code.cgi

That will check your syntax and most non-runtime dependencies without running the code.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
I tried what tviman said and I still get the same error message. Can you show me exactly how you set up the header in your scripts? Like copy and paste it so I can tell what I've done wrong? Thanks so much.
 
You already have it in your code. It is,
Code:
#THIS SECTION OF CODE IS RESPONSIBLE FOR OPENING THE FILE
print &quot;Content-type: text/html\n\n&quot;;

That is the header in this situation. If that is not making out through STDOUT then your code must be failing to compile and run. If your code contains syntax errors, the first thing output will be an error statement, not a valid HTTP header. Try running your code from a command prompt as I showed in my previous post. That will help you debug your code.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top