<?php
/**
* Author: Jörg Reinholz, fastix WebDesign & Consult, Kassel, Germany, http://www.fastix.org
* This script comes with ABSOLUTELY NO WARRANTY!
* This script is free software, and you are welcome to redistribute it under certain conditions:
* Licence: GPL, Version 2
* -- http://www.gnu.org/licenses/gpl-2.0.html.
* -- http://www.gnu.de/documents/gpl-2.0.de.html ( deutsche Übersetzung )
**/
/** Manual:
* Usage:
* <?php define( 'DEBUG', 2 ); require_once 'plugins/use_strict.php'; ?>
* or:
* <?php require_once 'plugins/use_strict.php'; ?> - in this smart & short case DEBUG will set to 1
* The constant DEBUG is also used in this ways:
* DEBUG == 0 or smaller than 0:
* --->The script will NOT break on notices or warnings but show them the notices or warnings, not the source!
* DEBUG == 1 or greater than 2:
* --->The script will hard break on ALL notices and warnings, but not show the source of the errors... ( standard )
* DEBUG == 2;
* --->The script will show the erroreus source & break on ALL notices and warnings...
* Editors - If you use Windows and have Errors
* Do not safe this with a BOM! Maybe your Skripts can not work fine if you do this.
* Show the fine manual of your text-editor.
**/
header_remove( );
header( "Cache-Control: no-store, no-cache, must-revalidate" );
header( $_SERVER['SERVER_PROTOCOL'].'/1.1 500' );
header( 'Content-Type: text/html; charset=utf-8' );
}
$msg = "$errStr in $errFile on line $errLine";
if ( $errNo == E_NOTICE ) { $errType = "notice"; }
elseif ( $errNo == E_WARNING ) { $errType = "warning"; }
elseif ( $errNo == E_USER_WARNING ) { $errType = "self triggered warning"; }
elseif ( $errNo == E_USER_NOTICE ) { $errType = "self triggered notice"; }
elseif ( $errNo == E_USER_ERROR ) { $errType = "self triggered error"; }
else { $errType = "unknown"; }
if ( $errType ) {
if ( 2 == DEBUG ) {
$arErrFile = file( $errFile );
$errMin = $errLine - 4; if ( $errMin < 1 ) { $errMin = 1; }
$errMax = $errLine - 1; if ( $errMax >= count( $arErrFile ) ) { $errMax = count( $arErrFile ) - 1 ; }
for ( $i = $errMin; $i <= $errMax; $i++ ) {
if ( ( $i > 1 ) && ( isset( $arErrFile[$i] ) ) ) {
if ( $i == $errLine - 1 ) {
$arErrText[] = "<b>$i:</b>\t<span style = 'border:1px solid red;'>" . htmlspecialchars( rtrim( $arErrFile[$i] ) ). "</span>\n";
} else {
$arErrText[] = "<b>$i:</b>\t<span>" . htmlspecialchars( $arErrFile[$i] ) . "<span>";
}
}
}
} else {
$arErrText[0] = "If you wish to see the relavant part of th source here, then define DEBUG und set this to 2.";
}
$my_php_error_msg_id = 'phperr_'.rand( );
$errStr = preg_replace( "/ \[<a href='.*'>.*<\/a>\]/", "", $errStr );
if ( 0 < DEBUG ) {
$errBreaked = "The execution of your fine script was hard breaked. Why?";
$errScript = '';
} else {
$errBreaked = '<button onclick="closer_'.$my_php_error_msg_id.'( );">close this message</button> --- ';
$errScript = "
<script type=\"text/javascript\">
if ( 'number' == typeof( phperr_zindex ) ) {
phperr_zindex = phperr_zindex - 1;
} else {
phperr_zindex = 950;
}
document.getElementById( '$my_php_error_msg_id' ).style.zIndex = phperr_zindex;
function closer_".$my_php_error_msg_id."( ) {
while( o = document.getElementById( '$my_php_error_msg_id' ) ) {
o.parentNode.removeChild( o );
}
}
</script>
";
}
#The first line of the output is helpful if the calling script works in a special context. Naturally is this not valid html...
print "<!-- ]]\"' --></script></style></iframe></frame></frameset></noscript>
<div style = 'position:absolute;z-index:9999;top:0;left0;width:80%;border:1em solid red;padding:.5em;color:#008;background-color:#fff;display:block' id = '$my_php_error_msg_id'>
<h1>Error! ( Type: "$errType" )</h1>
<ul>
<li><strong>in file:</strong> <pre>" . htmlspecialchars( $errFile ) . "</pre></li>
<li><strong>in row:</strong> " . ( $errLine - 1 ) . "</li>
<li><strong>the most relevant part of code:</strong> <pre>" . implode( '', $arErrText ). "</pre></li>
</ul>
<p><strong>$errBreaked Often the results are not this what expected!</strong></p>
</div>
$errScript
";
if ( 0 < DEBUG ) {
}
} else {
echo $msg;
}
}, E_ALL );