In general, you'll find that you will save yourself a lot of grief if you print your header as early as possible in your script. That way if something goes wrong and you print an error message, it won't confuse the browser (which expects a particular Content-Type message as the first output of your script.

I use the fatalsToBrowser and warningsToBrowser in CGI::Carp recommended by Joost and ikegami extensively.

Remember, the user under which a CGI script is executed through the webserver is generally different from the command-line environment user, and will often lack file permissions and environment variables that you expect it to have.

Update: I notice that you do not specify any path for the password.txt file -- that seems to be one very good reason why it may fail to open the file, and (as pointed out by Joost, it will then print an error message which precedes the header (which is bad).


No good deed goes unpunished. -- (attributed to) Oscar Wilde

In reply to Re: CGI Login script error by ptum
in thread CGI Login script error by mattdope

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.