我知道你說錯誤報告已啓用,但我想我會問:它是如何啓用的? 99%的時間我看過你描述的是因爲錯誤報告被禁用。
下面是一個快速測試,看看它是否是PHP錯誤。以下代碼會在發生PHP錯誤時通過電子郵件發送給您。我經常做的是把它放到一個名爲「errorhandler.php」的文件中,並將該文件包含在其他PHP文件中以啓用此錯誤處理程序。您需要根據自己的情況調整它... E.G.更改「YOURDOMAIN」和「YOUREMAIL」:-)
<?php
function reportError($errorNumber, $errorString, $errorFile = false, $errorLine = false, $errorContext = false)
{
global $php_errormsg,$config,$system;
$domainName = $_SERVER['HTTP_HOST'];
$longDate = date("F j, Y g:i:s A O");
$errorContext_ht = '<pre>'.htmlspecialchars(print_r($errorContext,true)).'</pre>';
$backtrace = debug_backtrace();
//$backtrace_ht = eval("return print_r(\$backtrace,true);");
$backtrace_ht = '<pre>'.htmlspecialchars(print_r($backtrace,true)).'<pre>';
$url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'N/A';
$errorNumber_human = '';
switch($errorNumber)
{
case E_ERROR: $errorNumber_human = ' (E_ERROR)'; break;
case E_NOTICE: $errorNumber_human = ' (E_NOTICE)'; break;
case E_WARNING: $errorNumber_human = ' (E_WARNING)'; break;
case E_PARSE: $errorNumber_human = ' (E_PARSE)'; break;
case E_CORE_ERROR: $errorNumber_human = ' (E_CORE_ERROR)'; break;
case E_CORE_WARNING: $errorNumber_human = ' (E_CORE_WARNING)'; break;
case E_COMPILE_ERROR: $errorNumber_human = ' (E_COMPILE_ERROR)'; break;
case E_COMPILE_WARNING: $errorNumber_human = ' (E_COMPILE_WARNING)'; break;
case E_USER_ERROR: $errorNumber_human = ' (E_USER_ERROR)'; break;
case E_USER_WARNING: $errorNumber_human = ' (E_USER_WARNING)'; break;
case E_USER_NOTICE: $errorNumber_human = ' (E_USER_NOTICE)'; break;
}
$error_env = compact('errorNumber', 'errorString', 'errorFile', 'errorLine', 'errorContext');
$html = <<<END_OF_HTML_MESSAGE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
body {
color: #000;
background-color: #fff;
font-family: Verdana, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
font-weight: normal;
font-variant: normal;
}
</style>
<body>
<div id="content">
<div id="header">
<h1>Website Error Report</h1>
<h2>{$domainName}</h2>
<h3>{$longDate}</h2>
</div>
<div id="errorReport">
<h2>Error Summary:</h2>
<dl>
<dt>Error Code</dt>
<dd>{$errorNumber}{$errorNumber_human}</dd>
<dt>Error String</dt>
<dd>{$errorString}</dd>
<dt>URL</dt>
<dd><a href="{$url}">{$url}</a></dd>
<dt>Error File</dt>
<dd>{$errorFile} line {$errorLine}</dd>
<dt>User Info</dt>
<dd><a href="http://ws.arin.net/whosi/?queryinput={$_SERVER['REMOTE_ADDR']}">{$_SERVER['REMOTE_ADDR']}</a>
using {$_SERVER['HTTP_USER_AGENT']}</dd>
<dt>Referrer</dt>
<dd><a href="{$referrer}">{$referrer}</a></dd>
<dt>PHP Error Message</dt>
<dd>{$php_errormsg}</dd>
<dt>Context</dt>
<dd>$errorContext_ht</dd>
<dt>Backtrace</dt>
<dd>$backtrace_ht</dd>
</dl>
</div>
</div>
</body>
</body>
</html>
END_OF_HTML_MESSAGE;
$subject = "{$domainName} Error!";
$headers .="From: [email protected]\r\n";
$headers .="Content-Type: text/html; charset=\"iso-8859-1\"\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
mail('YOUREMAILHERE',$subject,chunk_split(base64_encode($html)),$headers);
}
function __error($errorNumber, $errorString, $errorFile = false, $errorLine = false, $errorContext = false)
{
$fatal = false;
$msg = '';
// #108 ignore IIS SSL errors
if ($errorString == 'fgets(): SSL: fatal protocol error')
return false;
switch($errorNumber)
{
case E_NOTICE:
// We don't care about notices or warnings. Pass off to PHP.
return false;
case E_USER_NOTICE:
$msg = '';
break;
case E_USER_WARNING:
case E_WARNING:
$msg = <<< END_OF_HTML
<p style="_errorWarning">There were potential errors processing your request. Our staff has been notified.
Please make sure your request was properly fulfilled. If you need assistance please contact us.</p>
END_OF_HTML;
break;
case E_USER_ERROR:
case E_CORE_ERROR:
case E_ERROR: $fatal = true;
default:
$msg = <<< END_OF_HTML
<h1>Error</h1>
<h2>Your request could not be completed</h2>
<p>We're sorry but your request could not be completed. We have automatically composed an error report
which has been sent to the server administrator. Please try your request again, or email the staff and
request assistance.</p>
END_OF_HTML;
break;
}
echo $msg;
reportError($errorNumber, $errorString, $errorFile, $errorLine, $errorContext);
if($fatal)
{
$obLevel = @ob_get_level();
for($i=0;$i<$obLevel;$i++)
ob_end_flush();
exit();
}
return true;
}
set_error_handler('__error');
很高興你知道了! – Josh 2009-08-27 16:53:11