note 38417 deleted from function.exit by nlopess

From: Date: Sat, 20 Dec 2003 09:11:51 +0000
Subject: note 38417 deleted from function.exit by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62267@lists.php.net to get a copy of this message
Note Submitter: egypt@nmt.edu ---- <?php /** * pretty_die(): Send a pretty message to the user, log an error and exit * * If $_DEBUGGING is TRUE then print the error, otherwise, * write it to the log and show a pretty message to the user * * @uses HEADER Header to include when showing message. * @uses FOOTER Footer to include when showing message. * @uses $_DEBUGGING TRUE: print stuff. FALSE: log stuff and show a message. * @param int $line Line number of the error. * @param string $msg A short, useful message describing * why your script died. * @author James Lee */ function pretty_die($line = 0, $msg = "Something's wrong") { global $_DEBUGGING; include_once(HEADER); if ($_DEBUGGING) { // if we're debugging, print to the browser print "DEBUG: ". $msg ." on line ". $line ."<br />\n"; }else{ // otherwise, display an alert message and log the error. ?> <div class="alert">An error has occurred and will be logged by the system.</div> <p>Options: <ul> <li><a href='mailto webmaster?Subject=<?php print $_SERVER["PHP_SELF"]; ?>&body=Please check the error logs for this page.' >Notify Webmaster about this error.</a> </li> <li><a href="<?php print $_SERVER['HTTP_REFERRER']; ?>">Back</a></li> <li><a href='/'>Home</a></li> </ul> </p> <?php error_log($msg . " in " . $_SERVER['PHP_SELF'] ." on line ". $line); } include_once(FOOTER); exit; } // ---------------- // end pretty_die() // ---------------- ?> I wrote this to make dying a little nicer. When a user sees FATAL ERROR: ... they tend to freak out and complain to the IT department. =) With this they see something a little more friendly when your page breaks, but you can turn debugging on and see the error without having to go to the log.

« previous php.notes (#62267) next »