I don't like large error classes that do all sorts of fancy stuff. I also like text logs rather than database ones. Just my preference.
That said, here's the code:
Code: Select all
<?php
/**
* define ERRLOG to change location and/or filename of the log. (default: error.log)
* define ERRUSER as the user varialbe to log the user. (default: off)
* -- without $, as so: define("ERRUSER","_SESSION['user']");
* define ERRPAGE to produce a server error like page (default: off)
* define ERRLINE and use __LINE__ as a second parameter to log
* the line the error occurred on. (default: off) [if defined:(default: ??)]
*
* Example Use: err("Error message.");
* err("Error message.",__LINE__);
*/
function err($msg='Undefined Error',$line='??') {
$out = time().'|'.$msg.'|'.$_SERVER['REQUEST_URI'];
if (defined('ERRLINE')) {
$out .= '|'.$line;
$msg .= " ({$line})";
}
if (defined('ERRUSER')) {
$uservar = ERRUSER;
global $$uservar;
$user = isset($$uservar) ? $$uservar : 'G';
$out .= '|'.$user;
}
$log = defined('ERRLOG') ? ERRLOG : 'error.log';
$handle = @fopen($log,'a');
@fwrite($handle,$out."\n");
if (defined('ERRPAGE')) {
$err = 'Error'; // for the error page \/
require '/var/www/localhost/error/main.php';
die;
}
else die("<b>Error:</b> {$msg}");
}
?>How could I define the name of the user variable as something like $_SESSION['user'] and have it work right?
Also, any suggestions would be great great.