63 lines
2.5 KiB
PHP
63 lines
2.5 KiB
PHP
<?php
|
|
require_once(ROOT."include/db.inc.php");
|
|
require_once(ROOT."include/template.inc.php");
|
|
|
|
/** logs an error or warning
|
|
* @param severity severity: 1 (low) ... 5 (high)
|
|
* @param message error message
|
|
* @param file filename where the exception was thrown
|
|
* @param line line of code where the exception was thrown
|
|
*/
|
|
function logError($severity=1, $message="", $file="", $line=1, $code=500){
|
|
|
|
if (!isBot()) {
|
|
//save log to database
|
|
$query = sprintf("INSERT INTO bruckm_log (`date`, severity, message, file, line)
|
|
VALUES (NOW(), %d, '%s', '%s', %d)",
|
|
$severity,
|
|
addslashes($message),
|
|
addslashes($file),
|
|
$line);
|
|
dbQuery($query, false);
|
|
|
|
//notify the admin
|
|
if($severity >= 3){
|
|
$mail = "Severity: $severity\n" .
|
|
"Message: $message\n".
|
|
"Code: $file/$line\n".
|
|
"Log ID: ".mysql_insert_id() ."\n".
|
|
"SERVER: ".print_r($_SERVER, true)."\n".
|
|
"REQUEST: ".print_r($_REQUEST, true)."\n".
|
|
"SESSION: ".print_r($_SESSION, true)."\n";
|
|
@mail(ADMIN, "flexicon Error", $mail, "From: error@flexicon.com");
|
|
}
|
|
}
|
|
|
|
//stop execution if it is a really bad error
|
|
if($severity >= 5){
|
|
defaultErrorPage("", $code);
|
|
}
|
|
}
|
|
|
|
/** shows a default error page
|
|
* @param message error message
|
|
*/
|
|
function defaultErrorPage($message="", $code=500){
|
|
header('X-PHP-Response-Code: ' . $code, true, $code);
|
|
$t = new Template(TEMPLATE_DIR."errorpage.html");
|
|
$t->setVar("MESSAGE", $message);
|
|
die($t->toString());
|
|
}
|
|
|
|
/** check if the request came from a bot
|
|
* @return boolean true if it is a bot
|
|
*/
|
|
function isBot() {
|
|
if (isset($_SERVER['HTTP_USER_AGENT'])) {
|
|
return strpos($_SERVER['HTTP_USER_AGENT'], 'bingbot') !== false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
?>
|