阮一峰的IT笔记:首页 -> 分类 -> PHP 查看所有文章:按分类 | 按月份

一个PHP错误处理范例

// Decide what errors to report:
error_reporting (E_ERROR | E_WARNING | E_NOTICE);
// Webmaster email and error page url:
$Wmemail = 'you@ursite.com';
$ErrorPage = 'http://www.ursite.com/error.html';
// This function will check the error type:
function MailErrorHandler($errno, $errstr, $errfile='?', $errline= '?')
{
global $Wmemail, $ErrorPage;
if (($errno & error_reporting()) == 0)
return;
$err = '';
switch($errno) {
case E_ERROR: $err = 'FATAL'; break;
case E_WARNING: $err = 'ERROR'; break;
case E_NOTICE: return;
}
// Send the error details via email:
mail($Wmemail,
"PHP: $errfile, $errline",
"$errfile, Line $errline\n$err($errno)\n$errstr");
// Redirect to the error page:
print '<META HTTP-EQUIV="Refresh" CONTENT="0;url='.$ErrorPage.'">';
die();
}
set_error_handler('MailErrorHandler');
?>

« MySQLi函数库 | 首页 | Error Handling in PHP: Coding Defensively »

About

This page contains a single entry from the blog posted on 2007年11月17日 21:01.

The previous post in this blog was MySQLi函数库.

The next post in this blog is Error Handling in PHP: Coding Defensively.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33

Post a comment