Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is dienice???
by tachyon (Chancellor) on Aug 19, 2004 at 08:36 UTC | |
In a CGI if you do:
then the user will not get an error message. Typically they will get a 500 internal server error or a blank screen, depending on if a header has been output. They will not see the error message. A die nice routine might be:
So rather than die-ing you die nice ie do some stuff you want. You could just set a DIE handler but..... cheers tachyon | [reply] [d/l] [select] |
|
Re: What is dienice???
by davorg (Chancellor) on Aug 19, 2004 at 09:03 UTC | |
As tachyon says, the "dienice" function is a function which makes your errors look prettier than the standard "internal error" page. They have become popular largely thru their use in a number of beginners' CGI books. However, there's one important point to note with a "dienice" routine. tachyon's version does the right thing by simply displaying a vague error message to the user, but many versions from books display the complete error message to the user. This is generally a bad idea. Giving actual Perl error messages to users should be avoided. It will probably confuse your users and it gives too much information to the black-hats. The generic "internal server error" page is the way it is for a very good reason. It gives the user all the information that is necessary. The important thing is to write the real error message into the web server error log where it belongs so the webmaster can see it. For this reason, I very rarely use a "dienice" function, prefering to write a custom 500 error page which mirrors the look and feel of the web site.
-- <http://www.dave.org.uk> "The first rule of Perl club is you do not talk about
Perl club." | [reply] |
by tachyon (Chancellor) on Aug 19, 2004 at 11:23 UTC | |
Just to add to the custom 500 page theme.....
cheers tachyon | [reply] [d/l] |
by radiantmatrix (Parson) on Aug 19, 2004 at 13:27 UTC | |
It's very hard for, say, a visually-impaired person to have their assistance software try to distinguish between 'here' and 'here'. A better section would be:
| [reply] [d/l] |
by tachyon (Chancellor) on Aug 19, 2004 at 22:59 UTC | |
|
Re: What is dienice???
by gellyfish (Monsignor) on Aug 19, 2004 at 09:53 UTC | |
This is one of those moments where I wish I had one of those amnesia flash things from Men In Black. A quick survey via google has led me to believe that every example of code that uses the literal dienice subroutine out there is unadulterated crap, having been cut and pasted from some ancestral piece of mid 90's perl 4 code and hacked without any great understanding until it does what the person wanted. You probably do not want to be using this code as an example of good Perl programming. Of course I am probably being entirely unfair to some very good examples of code but there you go. In addition to the comments of tachyon and davorg, you might also want to look at the facilities offered by the module CGI::Carp which, through its fatalsToBrowser mode and the set_message subroutine allows you to catch to catch a die and then present your own message to the users browser, of course it is unwise to be showing the real error message to the whole world but it often makes debugging easier, so you can for instance check if the request is coming from your IP and if so show the whole error otherwise showing a bland message:
/J\ | [reply] [d/l] [select] |
|
Re: What is dienice???
by rinceWind (Monsignor) on Aug 19, 2004 at 13:54 UTC | |
Does fatalsToBrowser give too much information to a cracker? -- | [reply] |