Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Malformed Header Error

by macPerl (Beadle)
on Jul 19, 2004 at 16:18 UTC ( [id://375597]=perlquestion: print w/replies, xml ) Need Help??

macPerl has asked for the wisdom of the Perl Monks concerning the following question:

I recently have had to move some scripts to a new server and have run into a problem. Scripts that worked perfectly on the old server are returning a 500 error (Malformed Header).

A (Hello world!) test script which fails with the above error is:
#!/usr/bin/perl use CGI qw(:standard); use strict; sub printpage(); printpage(); exit; sub printpage(){ print << "EOF"; <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/T +R/html4/loose.dtd"> <html> <head> <title>Thanks for your request </title> </head> <body> <p>Thanks for submitting your information. We will get back to you sho +rtly</p><br> </body> </html> EOF }
This works as expected running locally but generates the error on the server.

Server config:
Operating system ... Linux
Kernel version ... 2.4.26
Apache version ... 1.3.31 (Unix)
PERL version ... 5.8.1
Path to PERL ... /usr/bin/perl


Has anybody experienced this before?
I think it must be something to do with the Apache/suExec config - but as I am still a Perl novice would like to have a sanity check (while I await a response from my hosting co).

Replies are listed 'Best First'.
Re: Malformed Header Error
by borisz (Canon) on Jul 19, 2004 at 16:31 UTC
    You need to print out some headers before the page content.
    print "Content-type: text/html\n\n";
    or even better
    print header(-type => 'text/html');
    Boris
      Thanks for responding - but, having tested, that is not the solution. I was (am?) under the impression that the Document Type Declaration
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML .01//EN" "http://www.w3.org/TR/html4/loose.dtd">
      superseded the header
      Content-type: text/html.

      No ? Note, I generally use the "Strict DTD" but left in "loose" in this test in order to rule out that possibility.
        No, you need a content-type header. the header need to send out, before the content.
        #!/usr/bin/perl use CGI qw(:standard); use strict; sub printpage(); print header( -type => 'text/html'); printpage(); exit;
        Boris
        No.DOCTYPE declarations are ADDITIONAL to the content-type. If you set content-type to "text/plain" for instance, the browser should ignore any markup in the file and just show it as plain text with funny tags in it.

        You need a valid content-type header. Sometimes this is automatically provided by the webserver, but most of the time, it isn't.

        Also, you might have uploaded your perl script as binary with different line-endings than the line-endings on the target machine, or your script is not executable by the webserver user (do chmod 755 filename).

Re: Malformed Header Error
by ccn (Vicar) on Jul 19, 2004 at 16:28 UTC

    It can be DOS newlines have been appeared on file transfer from one place to another. They looks like '^M' characters at end of lines in vi or emacs editors

    Upd: I missed that your script doesn't print http header. Please insert print header(); before any print

      I am arranging telnet access to check on the server.

      As part of my troubleshooting I tested when sent both as Binary and Text (just in case).

      Also, would this not also affect .htm files uploaded? I have experienced no problem there.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://375597]
Approved by ccn
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found