improved error handling and reporting
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<!-- Unicode Reminder メモ -->
|
||||
<head>
|
||||
<title>Opencaching.de - Datenbankproblem</title>
|
||||
<title>Opencaching.de - Interner Fehler</title>
|
||||
<meta http-equiv="content-type" content="text/xhtml; charset=UTF-8" />
|
||||
<meta http-equiv="Content-Language" content="de" />
|
||||
<meta http-equiv="gallerimg" content="no" />
|
||||
@@ -13,7 +13,7 @@
|
||||
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
||||
<tr>
|
||||
<td width="80px">
|
||||
<a href="/index.php"><img src="images/newlogo.png" alt="oc-Logo" style="border:0px;"/></a>
|
||||
<a href="index.php"><img src="images/newlogo.png" alt="oc-Logo" style="border:0px;"/></a>
|
||||
</td>
|
||||
<td width="100%">
|
||||
|
||||
@@ -24,19 +24,20 @@
|
||||
</tr>
|
||||
</table>
|
||||
<div id="content">
|
||||
<h1>Fehler beim Datenbankzugriff</h1>
|
||||
<?php
|
||||
require('lib/settings.inc.php');
|
||||
// no references to any other PHP code here except $errtitle and $errmsg, to minimize
|
||||
// possibilities of error recursions
|
||||
|
||||
echo '<p>Entschuldigung, bei der Darstellung der Seite ist ein interner Fehler aufgetreten.
|
||||
echo "<h1>" . $errtitle . "</h1>";
|
||||
echo '<p>Entschuldigung, bei der Darstellung der Seite ist ein intener Fehler aufgetreten.
|
||||
Falls dieses Problem für längere Zeit bestehen sollte, informiere uns bitte per
|
||||
<a href="mailto:' . $emailaddr . '">Email</a>.</p>
|
||||
<p>' . $dberrmsg . '</p>
|
||||
<a href="mailto:contact@opencaching.de">Email</a>.</p>
|
||||
<p class="errormsg">' . $errmsg . '</p>
|
||||
<p><a href="index.php">Zurück zur Startseite</a></p>
|
||||
|
||||
<p><br /><br /><em>An error occured while displaying the requested page.
|
||||
If this problem persists for a longer time, please inform us via
|
||||
<a href="mailto:' . $emailaddr . '">email</a>.</em></p>';
|
||||
<a href="mailto:contact@opencaching.de">email</a>.</em></p>';
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
@@ -50,9 +50,12 @@
|
||||
require_once($opt['rootpath'] . 'lib/settings.inc.php');
|
||||
require_once($opt['rootpath'] . 'lib/calculation.inc.php');
|
||||
require_once($opt['rootpath'] . 'lib/consts.inc.php');
|
||||
require_once($opt['rootpath'] . 'lib2/errorhandler.inc.php');
|
||||
|
||||
// timezone
|
||||
// basic PHP settings
|
||||
date_default_timezone_set($timezone);
|
||||
if ($debug_page)
|
||||
register_errorhandlers(); // not for production use yet, must be tested
|
||||
|
||||
$dblink_slave = false;
|
||||
$db_error = 0;
|
||||
@@ -460,10 +463,10 @@
|
||||
if ($interface_output == 'html')
|
||||
{
|
||||
// display errorpage
|
||||
$dberrmsg = $dberrormsg . ($debug_page ? "<br />" . $msql_error : "");
|
||||
$errmsg = $dberrormsg . ($debug_page ? "<br />" . $msql_error : "");
|
||||
if ($db_error <= 1)
|
||||
{
|
||||
tpl_errorMsg('sql_error', $dberrmsg);
|
||||
tpl_errorMsg('sql_error', $errmsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -471,7 +474,8 @@
|
||||
// build the error template (e.g. because connection was lost, or an error mail
|
||||
// could not load translations from database)
|
||||
|
||||
require("html/dberror.php");
|
||||
$errtitle = "Datenbankfehler";
|
||||
require("html/error.php");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
if (!isset($style)) $style = 'ocstyle';
|
||||
|
||||
//pagetitle
|
||||
if (!isset($pagetitle)) $pagetitle = 'www.opencaching.de';
|
||||
$pagetitle = 'local.opencaching.de';
|
||||
$opt['page']['title'] = 'OPENCACHING';
|
||||
$opt['page']['subtitle1'] = 'Geocaching with Opencaching';
|
||||
$opt['page']['subtitle2'] = '';
|
||||
|
||||
@@ -54,6 +54,7 @@ function __autoload($class_name)
|
||||
$opt['debug'] = $opt['debug'] & ~DEBUG_TRANSLATE;
|
||||
}
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/errorhandler.inc.php');
|
||||
configure_php();
|
||||
|
||||
require($opt['rootpath'] . 'lib2/cookie.class.php');
|
||||
@@ -139,6 +140,9 @@ function configure_php()
|
||||
ini_set('display_errors', true);
|
||||
ini_set('error_reporting', E_ALL);
|
||||
ini_set('mysql.trace_mode', true);
|
||||
|
||||
// not for production use yet (has to be tested thoroughly)
|
||||
register_errorhandlers();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -895,11 +895,14 @@
|
||||
// build the error template (e.g. because connection was lost, or an error mail
|
||||
// could not load translations from database)
|
||||
|
||||
$dberrmsg = 'MySQL error (' . $errno . '): ' . $error;
|
||||
require("html/dberror.php");
|
||||
if ($opt['db']['error']['display'] == true)
|
||||
$errmsg = 'MySQL error recursion (' . $errno . '): ' . $error;
|
||||
else
|
||||
$errmsg = "";
|
||||
$errtitle = "Datenbankfehler";
|
||||
require("html/error.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$db['error'] = true;
|
||||
|
||||
if ($db['connected'] == false)
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* This is included from both lib1 and lib2.
|
||||
***************************************************************************/
|
||||
|
||||
$error_handled = false;
|
||||
|
||||
|
||||
function register_errorhandlers()
|
||||
{
|
||||
set_error_handler('errorhandler', E_ERROR);
|
||||
register_shutdown_function('shutdownhandler');
|
||||
}
|
||||
|
||||
function errorhandler($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
// will catch a few runtime errors
|
||||
|
||||
global $error_handled;
|
||||
|
||||
if (!$error_handled)
|
||||
{
|
||||
$error_handled = true;
|
||||
$errtitle = "PHP-Fehler";
|
||||
|
||||
$error = "($errno) $errstr at line $errline in $errfile";
|
||||
send_errormail($error);
|
||||
|
||||
if (display_error())
|
||||
$errmsg = $error;
|
||||
else
|
||||
$errmsg = "";
|
||||
|
||||
require(dirname(__FILE__) . "/../html/error.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function shutdownhandler()
|
||||
{
|
||||
// see http://stackoverflow.com/questions/1900208/php-custom-error-handler-handling-parse-fatal-errors
|
||||
//
|
||||
// will catch anything but parse errors
|
||||
|
||||
global $error_handled;
|
||||
|
||||
if (!$error_handled &&
|
||||
function_exists("error_get_last") && /* PHP >= 5.2.0 */ ($error = error_get_last()) &&
|
||||
in_array($error['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR)))
|
||||
{
|
||||
$error_handled = true;
|
||||
|
||||
$error = "(" . $error['type'] . ") " . $error['message'] .
|
||||
" at line " . $error['line'] . " of " . $error['file'];
|
||||
send_errormail($error);
|
||||
|
||||
$errtitle = "PHP-Fehler";
|
||||
if (display_error())
|
||||
$errmsg = $error;
|
||||
else
|
||||
$errmsg = "";
|
||||
|
||||
require(dirname(__FILE__) . "/../html/error.php");
|
||||
}
|
||||
}
|
||||
|
||||
function display_error()
|
||||
{
|
||||
global $opt, $debug_page;
|
||||
return (isset($opt['db']['error']['display']) && $opt['db']['error']['display']) ||
|
||||
(isset($debug_page) && $debug_page);
|
||||
}
|
||||
|
||||
function send_errormail($errmsg)
|
||||
{
|
||||
global $opt, $sql_errormail, $absolute_server_URI;
|
||||
|
||||
if (isset($opt['db']['error']['mail']) && $opt['db']['error']['mail'] != '')
|
||||
{
|
||||
@mb_send_mail($opt['db']['error']['mail'], $opt['mail']['subject'] . " PHP error", $errmsg);
|
||||
}
|
||||
else if (isset($sql_errormail) && $sql_errormail != '')
|
||||
{
|
||||
$url = parse_url($absolute_server_URI);
|
||||
@mb_send_mail($sql_errormail, "[" . $url['host'] . "] PHP error", $errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user