Hi. I've created a page called error_reporting and including it in each page to trap errors. When I ran a page with the include file I got the error:
Parse error: parse error, unexpected '[', expecting ',' or ';' in /(path to file)/error_reporting.php on line 5
My code is here:
<?php
//create your error handler function
function handler($error_type, $error_message, $error_file, $error_line)
{
global $SERVER['HTTP_HOST'], $SERVER['HTTP_USER_AGENT'], $SERVER['REMOTE_ADDR'], $SERVER['REQUEST_URI'];
switch($error_type)
{
//fatal error
case E_ERROR:
$to = "Administrator <webmaster@daycentreconnections.org";
$subject = "Custom Error Handling";
$body = "<html>";
$body .= "<head>";
$body .= "<title></title>";
$body .= "</head>";
$body .= "<body>";
$body .= "<h1>Fatal Error</h1>";
$body .= "Error received was a <b>" . $error_type . "</b> error.<br>";
$body .= "The page that generated the error was: <b>" . $error_file . "</b>";
$body .= " and was generated on line: <b>" . $error_line . "</b><br>";
$body .= "The generated error message was:" . $error_message;
$body .= "</body>";
$body .= "</html>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Apache Error <host@yourdomain.com>\r\n";
$headers .= "Cc: [email]webmaster@daycentreconnections.org[/email]\r\n";
mail($to, $subject, $message, $headers);
die(); //kill the script
break;
//warnings
case E_WARNING:
$to = "Administrator <webmaster@daycentreconnections.org>";
$subject = "Custom Error Handling";
$body = "<html>";
$body .= "<head>";
$body .= "<title></title>";
$body .= "</head>";
$body .= "<body>";
$body .= "<h1>Warning</h1>";
$body .= "Error received was a <b>" . $error_type . "</b>
error.<br>";
$body .= "The page that generated the error was: <b>" .
$error_file . "</b>";
$body .= " and was generated on line: <b>" . $error_line .
"</b><br>";
$body .= "The generated error message was:" . $error_message;
$body .= "</body>";
$body .= "</html>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Apache Error <webmaster@daycentreconnections.org>\r\n";
$headers .= "Cc: [email]webmaster@daycentreconnections.org[/email]\r\n";
mail($to, $subject, $message, $headers);
break;
//script will continue
//notices
case E_NOTICE:
//don't show notice errors
break;
}
}
/
set error handling to 0
we will handle all error reporting
only notifying admin on warnings and fatal errors
don't bother with notices as they are trivial errors
really only meant for debugging
/
error_reporting(0);
//set the error handler to be used
set_error_handler("handler");
/
Create the rest of your page here.
We will not be displaying any errors
We will be e-mailing the admin an error message
Keep in mind that fatal errors will still halt the
execution, but they will still notify the admin
/
?>
I can't see what the problem is. Surely the [ is needed in the code?