Quantcast
Channel: archive Archives - The Fantastic Site of Lord Matt
Viewing all articles
Browse latest Browse all 42

My Blog:CMS wiki fix hack.

$
0
0

You are looking at an ancient archive from back in the day. It has been preserved here mostly out of nostalgia not because any of this is worth reading.

<?PHP
error_reporting(0);
	function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars) {
	    // timestamp for the error entry
    $dt = date("Y-m-d H:i:s (T)");
	    // define an assoc array of error string
    // in reality the only entries we should
    // consider are 2,8,256,512 and 1024
    $errortype = array (
                1   =>  "Error",
                2   =>  "Warning",
                4   =>  "Parsing Error",
                8   =>  "Notice",
                16  =>  "Core Error",
                32  =>  "Core Warning",
                64  =>  "Compile Error",
                128 =>  "Compile Warning",
                256 =>  "User Error",
                512 =>  "User Warning",
                1024=>  "User Notice"
                );
	    // set of errors for which a var trace will be saved
    $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
	    $err = "<errorentry>\n";
    $err .= "\t<datetime>".$dt."</datetime>\n";
    $err .= "\t&lt;errornum&gt;".$errno."</errnumber>\n";
    $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n";
    $err .= "\t<errormsg>".$errmsg."</errormsg>\n";
    $err .= "\t<scriptname>".$filename."</scriptname>\n";
    $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n";</p>
	    if (in_array($errno, $user_errors))
        $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n";
    $err .= "</errorentry>\n\n";
	    // for testing
    // echo $err;</p>
	    // save to the error log, and e-mail if there is a critical user error
    error_log($err, 3, "/usr/local/php4/error.log");
	    if ($errno == E_USER_ERROR) {
        mail("me@mydomain.com","Critical User Error",$err); 
        } else {
        echo '<meta http-equiv="refresh" content="0">' 
        }
}
	$old_error_handler = set_error_handler("userErrorHandler");
	?>

Archive notes

It might have helped if I had detailed the problem this was solving and where to put it. Even if all I did was explaining the code that would be something.

At a guess, this is a way to more elegantly handle errors. As I said, Blog:CMS was a horrible mess.

The worse thing is that in the same month I had complained of an open-source project not being clear about stuff. Pot, meet kettle.

The post My Blog:CMS wiki fix hack. appeared first on The Fantastic Site of Lord Matt.


Viewing all articles
Browse latest Browse all 42

Trending Articles