"
. htmlentities($shortMsg) . "\n"
. "An error has occurred. We apologise for the inconvenience and ask you to try again later.
\n"
. "Most likely, the webmaster is working on fixing this error at this very moment.
\n"
. "Go back to home to if refreshing this page does not help.\n";
// Run htmlentities over all, regardless
$details = array();
$details[] = "Date: " . strftime('%Y-%m-%d %H:%M:%S.') . sprintf('%06d', (int)substr(microtime(), 2, 6));
$details[] = "Detailed message:\n " . htmlentities($detailedMsg);
$details[] = "Croak namespace/object: [" . htmlentities($namespace) . "]";
if (isset($_SERVER['REMOTE_ADDR']))
$details[] = "Caller IP: [" . htmlentities($_SERVER['REMOTE_ADDR']) . "]";
if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI']))
$details[] = "Viewed URL: " . htmlentities("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]") . " ($_SERVER[REQUEST_METHOD])";
if (isset($_SERVER['HTTP_REFERER']))
$details[] = "Referrer URL: " . htmlentities($_SERVER['HTTP_REFERER']);
if (isset($_SERVER['HTTP_USER_AGENT']))
$details[] = "User-Agent: " . htmlentities($_SERVER['HTTP_USER_AGENT']);
// The backtrace
$backtrace = '';
$back = debug_backtrace();
while ($backtraceShift--)
array_shift($back);
foreach($back as $k => $v) {
$backtrace .= sprintf(" %-20s %s()\n", htmlentities(basename(@$v['file'])) . ':'
. htmlentities(@$v['line']), htmlentities(@$v['function']));
}
// Client data (not secret)
$cookie = serialize($_COOKIE);
$post = serialize($_POST);
// Session data (secret!)
$session = serialize(@$_SESSION);
$server = serialize($_SERVER);
// Send the message by mail if appropriate
if (KJW_EMAIL_ERRORS_TO != '') {
require_once(dirname(__FILE__) . '/KjwMail.php');
kjwmail_sendplain(
KJW_EMAIL_ERRORS_TO,
'KjwLib::kjw_croak: ' . substr($shortMsg, 0, 40),
$shortTextMsg . "\n[DETAILS]\n * " . implode("\n * ", $details) . "\n\n[BACKTRACE]\n$backtrace\n"
. "[POST]\n $post\n\n[COOKIE]\n $cookie\n\n[SESSION]\n $session\n\n[SERVER]\n $server\n\n"
);
}
// Add the message to a trace log
kjw_trace($shortMsg, 'ERROR', $namespace);
kjw_trace("DETAILS\n * " . implode("\n * ", $details), 'DEBUG', $namespace);
kjw_trace("BACKTRACE\n$backtrace", 'DEBUG', $namespace);
kjw_trace("POST = $post", 'DEBUG', $namespace);
kjw_trace("COOKIE = $cookie", 'DEBUG', $namespace);
kjw_trace("SESSION = $session", 'DEBUG', $namespace);
kjw_trace("SERVER = $server", 'DEBUG', $namespace);
// Display the message
if (!$print_html) {
echo $shortTextMsg;
if (KJW_EMAIL_ERRORS_TO == '')
echo "\n[DETAILS]\n * ", implode("\n * ", $details), "\n\n[BACKTRACE]\n", $backtrace;
} else {
// Break out of all sorts of html crapzola.
echo "
\n";
// Assemble total message
$totalMsg = "
[DETAILS]\n * " . implode("\n * ", $details) . "\n\n[BACKTRACE]\n$backtrace\n"; $totalMsg .= "