Hi there
I am trying to create a customized error handling function in php. I have used the set_error_hanler() function to divert errors to this function. The code seems pretty generic, but it does not want to work.
I have used the following code, which is included in the main page.
<?php
function custom_error_handler($errno, $errstr, $errfile, $errline)
{
$error_msg = " $errstr occured in $errfile on $errline at " . date("D M j G:i:s T Y");
$email_addr = "";
$log_file = "error_log.txt";
$email = false;
$stdlog = true;
$display = true;
$notify = false;
$halt_script = true;
switch($errno)
{
case E_USER_NOTICE:
case E_NOTICE:
$halt_script = false;
$type = "Notice";
break;
case E_USER_WARNING:
case E_COMPILE_WARNING:
case E_CORE_WARNING:
case E_WARNING:
$halt_script = false;
$type = "Warning";
break;
case E_USER_ERROR:
case E_COMPILE_ERROR:
case E_CORE_ERROR:
case E_ERROR:
$type = "Fatal Error";
break;
case E_PARSE:
$type = "Parse Error";
break;
default:
$type = "Unknown Error";
break;
}
if($notify)
{
$error_msg = $type . $error_msg;
if($email) error_log($error_msg, 1, $email_addr);
if($display) echo $error_msg;
if($stdlog)
{
if($log_file = "") {
error_log($error_msg, 0);
} else {
error_log($error_msg, 3, $log_file);
}
}
}
if($halt_script) exit -1;
}
//define custom error handler
set_error_handler("custom_error_handler");
?>
Any suggestions as to what the error could be?
Thanks
langals