note 38417 added to function.exit
| From: | egypt at nmt dot edu | Date: | Fri, 19 Dec 2003 20:16:24 +0000 |
| Subject: | note 38417 added to function.exit | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62254@lists.php.net to get a copy of this message | ||
<?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.
----
Manual Page -- http://www.php.net/manual/en/function.exit.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38417
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38417&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38417&report=yes
Search -- http://master.php.net/manage/user-notes.php