Gossamer Forum
Home : General : Perl Programming :

Premature ending of script headers

Quote Reply
Premature ending of script headers
I keep getting the error message "Premature ending of script headers." I know that I have uploaded the file in ASCII mode and that the path to perl is correct. What other things should I be looking for?

------------------
JPD





Quote Reply
Re: Premature ending of script headers In reply to
Hiya Carol,

Usually it's something simple like a missing semicolon or bracket or something.

Usually. Smile

adam
Quote Reply
Re: Premature ending of script headers In reply to
Well, I've checked it for syntax error and didn't get any.

This is for my new file-upload mod and some people are having success with it while others aren't. There's a separate .cgi file that is used for the upload that is causing the problem. It doesn't require any editing at all, so the file itself is the same for everyone. I'm having a heck of a time figuring out why it's working for some people and not for others.



------------------
JPD





Quote Reply
Re: Premature ending of script headers In reply to
This probably doesn't answer your question at all, but I was getting that error message while modifying a script that uses the

print "
";

format (with " escaped by \). I finally found the line creating the error. It was a <table border=\"0\" width=.....> line with all the quotes escaped correctly. I checked it at least 20 times! Frown When I took out every \" (I prefer to surround numbers by quotes, as I learned that's ther 'proper' method) in that line, it worked fine. Just that one line, go figure.

The only conclusion I can draw from this in your case is that funny things happen. Maybe try commenting out sections until you find the troublesome one -- that's how I found mine -- and fiddle with it to see if it works better.

Dan
Quote Reply
Re: Premature ending of script headers In reply to
Hi again Carol,

Well, maybe my answer was a bit obvious. Anyway, I agree with Dan, commenting portions of the code is usually how I debug as well, although again, that's probably obvious. Did you try adding:

Code:
use CGI::Carp qw/fatalsToBrowser/;
$|++;

...to the top of your script? Sometimes that sends an error to the browser that won't appear in the error_log.

I see the mod isn't on your site yet, so do you want to post it here or on the site? Somebody might be able to spot what's happening. Or you can send it to me if you want and I can at least see if it works for me. Use adam@adambeecher.com if you do though, or I mightn't get it for ages! Smile

Cheers,
adam
Quote Reply
Re: Premature ending of script headers In reply to
I do have it on my site, but it's not ready for "prime time" as yet. It's working fine for me. It's just not working for someone else.

So far I have (aside from me) two successes and one failure. Same script.

I'm wondering if it could be the CGI.pm module. If my guy who's having problems didn't have it installed on his server, would that give this error message? The mod requires CGI.pm.

I suggested that he ask his server admin about it, just to be sure.


------------------
JPD





Quote Reply
Re: Premature ending of script headers In reply to
That could quite possibly be the problem. Somebody on the FileMan forum was getting "Premature end of script headers" errors with the script because he didn't have the vars.pm and cgi.pm modules.

Ask him to look at his error log and see if he was getting errors like those listed in gossamer-threads.com/scripts/forum/resources/Forum7/HTML/000070.html . If he was, that's yer kiddy!

adam

[This message has been edited by dahamsta (edited May 13, 1999).]
Quote Reply
Re: Premature ending of script headers In reply to
Thanks much, Adam! This may be it.

Why it didn't occur to me before, I'll never know. I'm gettin' slow these days. Smile



------------------
JPD





Quote Reply
Re: Premature ending of script headers In reply to
JPD - I think I may have found the problem. Our server admin says that CGI.pm is in fact installed on the server.

However, I saw Adam's post about adding the error checking code and this is what was returned to my browser.

"Software error:
Undefined subroutine &main::auth_cleanup called at file-upload.cgi line 56. "

The only thing is now - I don't know what it means? :-)

-------
Donm
Quote Reply
Re: Premature ending of script headers In reply to
Well, at least that narrows it down.

It means that, for some reason, it's not finding the auth.pl script in the directory.

We'll get it sorted out.


------------------
JPD





Quote Reply
Re: Premature ending of script headers In reply to
Yes, that is exactly what it means. But, why? I dunno?

-------
Donm
Quote Reply
Re: Premature ending of script headers In reply to
Well, Carol probably knows more about your setup than I do, but maybe you could try changing the line that requires the auth.pl script to a proper server path?

It's about line 45 in db.cgi:

Code:
require "auth.pl"; # Authorization Routines

Just change it to:

Code:
require "/path/from/root/to/auth.pl";

Can't do any harm to try anyway? Smile

adam
Quote Reply
Re: Premature ending of script headers In reply to
Ok - now I have per JPD's instructions added the auth.pl to the file-upload.cgi script rather than just pointing to it.

We now are getting closer - I now receive the following error:

"CGI ERROR==================================
Error Message : The directory you specified isn't really a directory.
Make sure that this is indeed a directory and not a file."

hmmmmm?
Quote Reply
Re: Premature ending of script headers In reply to
I really think we should end this now. Most folks have no idea of the script we're talking about and it would take too long to explain everything. I really just wanted to find out what reasons a script might give the error message.

Thanks everyone for all your suggestions!


------------------
JPD





Quote Reply
Re: Premature ending of script headers In reply to
A little late, but here's some debugging suggestions. If you are getting a premature end of script headers, it usually means that your script is printing something before printing the headers. If there is nothing in the error log, then adding:

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

at the very beginning of the script usually helps. You can then see exactly what was outputted.

Cheers,

Alex
Quote Reply
Re: Premature ending of script headers In reply to
Thanks Alex!

What we finally figured out was that the script required a specific path to other files in the directory. It was odd to me, because DBMan on that server didn't require it and other folks that have used this mod (file upload) didn't require it. It seemed to be a combination of the server and CGI.pm.

After much consternation, we finally got it to work, though. :-)

Thanks much for all the help.


------------------
JPD