Along the lines of using a global, I cram my own flag right into the cgi object.

Yeah, probably not the best idea, as my variable just might clobber some internal CGI variable, but, hey, it works...

So whenever I start a new page, anywhere within my system of cooperating CGI apps, I note the header was sent:
print $q->header(), $q->start_html(-title=>"R3: edit ads", -style=>{-code=>&css()}); $q->{header_was_sent}++;
And then in my error code (same code shared by all the scripts in the system), I can see if I need a header or not.

Since this on an intranet, and everyone using the apps is trusted and more-or-less SQL and database savvy, I send lots of info back to the user in the error call. (This would be a really bad idea for a public internet app!!!) Here's my error code:
sub error { my (@msgs) = @_; my $firstline = shift(@msgs); if (!$q->{header_was_sent}) { print $q->header(), $q->start_html(-title=>"R3: error", -style=>{-code=>&css()}); } print "<br><marquee><font class=\"error\"> Need help? Something busted? + Confused? Email the error message below to XXXXXXXXXXXXXXX </font>< +/marquee><br>", "<h1 class=\"error\"> Error: $firstline </h1><h2 class=\"error\">" +, scalar(localtime), "<br>", join ("<br>",@msgs), "</h2>\n"; print $q->end_html; exit(0); }
The marquee tag is annoying, but it gets noticed.

When I trap DBI errors, I send the error routine lots of information to help the user figure out what went wrong, including the sql itself and the DBI error string...
my @inqs = @{$dbh_g->selectcol_arrayref($sql,undef,$adid)} or &error +("Bad selectcol in get_inqs", $sql, $dbh_g->errstr);
Again, this level of openness is not suitable for open web!

In reply to Re: Did I already print a header? by nop
in thread Did I already print a header? by jptxs

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.