CGI Error - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

CGI Error

RazaRaza Posts: 53Member
Hi !

I am a Perl newbie. I recently added the IIS 5.1 component to my computer running Win XP and configured it to run CGI programs.I use SiePerl.
I save my programs in k:inetpubwwwrootcgi-bin.I can now successfully run programs from the browser using http://localhost/cgi-bin/.pl
But using using subroutines in my cgi programs is giving me a tough time.e.g.) When I run the following hello.pl from the browser using http://localhost/cgi-bin/hello.pl it gives me the following error :
[b]
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
htmlhead.pl did not return a true value at k:inetpubwwwrootcgi-binhello.pl line 1. [/b]

The following is the code for hello.pl.

[code]
require "htmlhead.pl";
require "htmlend.pl";

&html_header("What a wonderful day...");
print "

Hello World
";
&html_footer;
[/code]

Code for htmlhead.pl

[code]
sub html_header
{

print "Content-type:text/html

";

print "
";

print "
";

print "";

print "@_";

print "

";

print "
";
}
[/code]

And finally, the code for htmlend.pl

[code]
sub html_footer
{

print "

";

print "";

}

[/code]

Plz help...
Thank you :-)

Comments

  • WeirdofreakWeirdofreak Posts: 439Member
    From the error message, I'd guess that htmlhead.pl is returning false, so it doesn't get past the first require. To solve it, end the file with "1;" so that it returns true, or use do, which I don't think cares what the return value of the file is, instead of require. Also, you may want to put the subroutine declarations in the same file so you don't need to do two do/requires.

    It might also not be finding htmlhead.pl and htmlend.pl - check @INC to make sure it's looking in the right place, or the CWD if they should be found in (dot). The CWD can be obtained with
    [code]use CWD;
    $cwd = getcwd();[/code]

    Oh, and you might want to add a character encoding and doctype, and close that H1... ;-)
Sign In or Register to comment.