Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Did I already print a header?

by nop (Hermit)
on Dec 01, 2000 at 00:48 UTC ( #44217=note: print w/replies, xml ) Need Help??


in reply to Did I already print a header?

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://44217]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2018-07-19 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (411 votes). Check out past polls.

    Notices?