Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: Unintialised value?

by eoin (Monk)
on Jan 25, 2004 at 16:26 UTC ( [id://323979]=note: print w/replies, xml ) Need Help??


in reply to Re: Unintialised value?
in thread Unintialised value?

Fixed that problem but now have this:
[Tue Jan 20 18:48:39 2004] [error] [client 159.134.228.95] Premature end of script headers: /home/eoin/public_html/cgi-bin/index. +cgi Can't open perl script "^M": No such file or directory
Any ideas??

Eoin.

Replies are listed 'Best First'.
Re: Re: Re: Unintialised value?
by Vautrin (Hermit) on Jan 25, 2004 at 22:03 UTC

    Some background info: (You may or may not know this -- included for completeness) CGI is a protocol whereby executable programs can be run on a web server in a controlled enviornment which allows them access to the outside world as securely as possible. (Thus, CGI != Perl as some people think. Basically, a CGI script has to do all the work Apache or another web server would do when sending web pages. This means reading in GET variables from $ENV, and outputting the proper headers. (This is unlike a language like PHP which does all this for you unless you tell it not to)).

    So whenever a CGI script sends a web page to a client browser it must print the following header first: (This is a bare minimum. There are many more headers that can be sent. Download a copy of Mozilla and install LiveHTTPHeaders. This lets you watch the headers sent back and forth between the browser and server -- which is useful for learning and debugging).

    use strict; use warnings; #$content_type is the /mime/ type my $content_type = 'text/html'; print "Content-type: $content_type\n\n";

    Notice that the headers end with a blank new line. And these headers must be the first thing your script outputs, and they must be valid headers. And, of course, content type can change depending on whether you have an image (i.e. "image/jpeg" or "image/gif"), or XML (i.e. "application/xml" ("text/xml" is considered deprecated because it defaults to ASCII and not UTF)).

    Now, usually you'll write a function to do all of this for you, or you'll use CGI; in your script so that you don't have to create headers manually. But you still need to print out the headers, in the case of the CGI module it would be:

    use strict; use warnings; use CGI; my $content_type = 'text/html'; my $web_page = "<h1>hello world</h1>"; my $CGI_obj = $CGI_obj->new; # either: print $CGI_obj->header($content_type); # or (uncomment 1 line below and comment 1 line above) # print "Content-type: text/html\n\n"; print $CGI_obj->start_html; print $web_page; print $CGI_obj->end_html;

    The error message in your log files is saying that no headers were printed. This should be the very first thing your script outputs If you don't print them before anything else and use valid headers you will get that error. (Hint: use CGI.pm so you don't need to learn the entire HTTP standard. It's got lots of options for headers you probably never even knew existed).

    Also, if Carriage Returns (^Ms) which are a staple of Microsoft files are evil in the unix world. Make sure you are saving your scripts in Unix file format. If you don't, no interpreter will be found, and you'll get errors. That may be what that second error is.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found