phpErrorReporter.php
Version 1.0
February 19, 2013
phpErrorReporter consists of one php script file which you can upload anywhere on your server:
phpErrorReporter.php
Make phpErrorReporter operational
To make it operational you need to set some parameters:
// Full path to error log file
define("PHP_ERROR_REPORTER_LOG_FILE_PATH", "/full/path/to/phpError.log");
// Email address of webmaster or administrator
define("PHP_ERROR_REPORTER_EMAIL_TO", "webmaster@{$_SERVER['SERVER_NAME']}");
// Extra email headers: email from
define("PHP_ERROR_REPORTER_EMAIL_FROM", "From: phpErrorReporter@{$_SERVER['SERVER_NAME']}");
// Email intro
define("PHP_ERROR_REPORTER_EMAIL_INTRO", "Please do not reply to this email.\nThis is an automated message from phpErrorReporter at the indicated domain\n\n");
// Browser feed back top line
define("PHP_ERROR_REPORTER_FEEDBACK1", "<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' content='text/html; charset=iso-8859-1'>
<title>Error Report | {$_SERVER['SERVER_NAME']}</title>
<style type='text/css'>
h2 {
font-family:Verdana, Helvetica, Arial, sans-serif;
font-size:1.5em;
}
</style>
</head>
<body>
<h2>This system is temporarily unavailable</h2>
<p>The following has been reported to the administrator:</p>\n");
// Browser feed back bottom line
define("PHP_ERROR_REPORTER_FEEDBACK2", "<p>Sorry for the inconvenience.</p>
<div style=\"margin-top:50px;font-size:0.9em;\">
<strong>phpErrorReporter.php</strong><br>
<a href=\"http://softwaretimes.com/downloads/update+the+ultimate+php+er.html\" target=\"_blank\">The Ultimate Error Reporter</a><br>
Copyright 2011 - 2013, Denny Schlesinger<br>
</div>
</body>
</html>\n");
Next set the timezone if you don't want to use the server default timezone:
// use default server timezone
// $timeZone = date_default_timezone_get();
// or set custom timezone
$timeZone = 'America/Caracas';
phpErrorReporter is now ready to use. Upload it to your server.
Activate phpErrorReporter
To make it operational you need to add a few lines to your root htaccess file:
// htaccess for phpErrorReporter
# activate phpErrorReporter
php_value auto_prepend_file /full/path/to/phpErrorReporter.php
# php error handling for production servers
php_flag display_errors off
php_flag log_errors on
php_value error_log /full/path/to/phpError.log
Enable Error 500 reporting
Error 500 reporting requires a custom error page which is enabled in .htaccess:
# custom error pages
ErrorDocument 500 /path/to/error500.php
At the top of the error500.php page include the following php code:
<?php
// if phpErrorReporter enabled
if(function_exists('errorreporter')) {
trigger_error("Error 500", E_USER_ERROR);
}
// else, fall through and do a normal Error 500 page
$base = $_SERVER['HTTP_HOST'];
?>
The error500.php page needs a <base> tag
<base href="http://<?php echo $base; ?>/">
Test phpErrorReporter
You can use the error-tester.php file to test your installation. Uploaded it anywhere and run it. Of course, it will stop running at the first Fatal error. To test the other cases you need to comment out previous lines that cause Fatal errors. This is best done with an ftp utility that lets you edit the files directly on the server, for example BBEdit or Interarchy for Mac.
Log reader
Customize the username and the path/to/phpError.log
Upload the log-reader.php file to your server. It will list the contents of the error log.
To delete or edit the error log you still have to ftp the server but I'll add something to the log reader to make it more versatile.
That's It!
Now hope you don't get any email alerts from phpErrorReporter but if you do, be ready to debug your server.
Enjoy!
Read all about it!
The Ultimate PHP Error Reporter
Denny Schlesinger
Copyright 2011 - 2013 © Denny Schlesinger