I'm trying to have a cgi script use a string from the window location in a template file. When I run the script I get Internal Server Error and when I go to my control panel error log it says Premature end of script headers. I was wondering if some experienced programmer would take a look at it and see what is wrong with it:
That's usually an indication that you have a syntax error in the script.
And sure enough:
vnix$ perl -c /tmp/cgi
Bareword found where operator expected at /tmp/cgi line 27, near "<title>Template"
(Missing operator before Template?)
Bareword found where operator expected at /tmp/cgi line 28, near "</head"
(Might be a runaway multi-line // string starting on line 27)
(Missing operator before head?)
Semicolon seems to be missing at /tmp/cgi line 29.
syntax error at /tmp/cgi line 26, near "head>"
Search pattern not terminated at /tmp/cgi line 32.
There's a wrapper module for CGI which displays these types of errors on the generated page instead of that dreaded 500 Internal Server Error. You should probably use that at least while developing. (Search for "errors to browser"; can't remember what the thing is called ... ah, here: use CGI::Carp qw/fatalsToBrowser/;.)
The thing is that I don't really know anything about perl programming. I'v tried to change some things in response to this, but with no luck. Do you have any idea what it is that needs to be done?
You're lacking a "print <<EOF" (and the corresponding EOF) inside the else part. Perl is seeing your bare HTML code and expecting it to be in Perl syntax, which obviously it's not.
If you edited the file on a Windows computer and uploaded it in "binary" mode, that would put the wrong line-ending terminators there. But I just tested, and it doesn't seem to matter, as long as the line endings are consistent throughout the file.
Just to be on the safe side, can you make a copy of the script, and see if that works:
Also just to make sure there is no insidious cache anywhere which is holding on to the old version still, try to give it a completely new name. Some hosts use various mechanisms for loading a script into the server once, and keep it there, and you need to jump through some hoops to replace a faulty script.
Again I am getting Internal Server Error. I'm using Ipswitch WS_FTP Professional and it automatically sends all .cgi files in ASCII mode. I'm running another cgi script in the same directory so this is quit the mistory...