Source for file bit_error_inc.php
Documentation is available at bit_error_inc.php
* Custom ADODB Error Handler. This will be called with the following params
* @version V3.94 13 Oct 2003 (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
* Set tabs to 4 for best viewing.
* Latest version is available at http://php.weblogs.com
if( !defined( 'BIT_INSTALL' ) && !defined( 'ADODB_ERROR_HANDLER' ) ) {
define( 'ADODB_ERROR_HANDLER', 'bitdb_error_handler' );
* Switch debug level in database
$gBitDb->debug( $pLevel );
if( !empty( $_SERVER['SCRIPT_URI'] )) {
error_log( "OUTPUT in {$_SERVER['SCRIPT_URI']}" );
foreach ($errlines as $txt) { error_log($txt); }
function bit_error_handler ( $errno, $errstr, $errfile, $errline, $errcontext= NULL ) {
// error_reporting() === 0 if code was prepended with @
case E_ERROR: $errType = 'FATAL ERROR'; break;
case E_WARNING: if( $reportingLevel & E_WARNING ) { $errType = 'WARNING'; } break;
case E_PARSE: if( $reportingLevel & E_PARSE ) { $errType = 'PARSE'; } break;
case E_NOTICE: if( $reportingLevel & E_NOTICE ) { $errType = 'NOTICE'; } break;
case E_CORE_ERROR: if( $reportingLevel & E_CORE_ERROR ) { $errType = 'CORE_ERROR'; } break;
case E_CORE_WARNING: if( $reportingLevel & E_CORE_WARNING ) { $errType = 'CORE_WARNING'; } break;
case E_COMPILE_ERROR: if( $reportingLevel & E_COMPILE_ERROR ) { $errType = 'COMPILE_ERROR'; } break;
case E_COMPILE_WARNING: if( $reportingLevel & E_COMPILE_WARNING ) { $errType = 'COMPILE_WARNING'; } break;
case E_USER_ERROR: if( $reportingLevel & E_USER_ERROR ) { $errType = 'USER_ERROR'; } break;
case E_USER_WARNING: if( $reportingLevel & E_USER_WARNING ) { $errType = 'USER_WARNING'; } break;
case E_USER_NOTICE: if( $reportingLevel & E_USER_NOTICE ) { $errType = 'USER_NOTICE'; } break;
case E_STRICT: if( $reportingLevel & E_STRICT ) { $errType = 'STRICT'; } break;
case E_RECOVERABLE_ERROR: if( $reportingLevel & E_RECOVERABLE_ERROR ) { $errType = 'RECOVERABLE_ERROR'; } break;
case E_DEPRECATED: if( $reportingLevel & E_DEPRECATED ) { $errType = 'DEPRECATED'; } break;
case E_USER_DEPRECATED: if( $reportingLevel & E_USER_DEPRECATED ) { $errType = 'USER_DEPRECATED'; } break;
default: $errType = 'Error '. $errno; break;
// Send an e-mail to the administrator
if( defined( 'IS_LIVE' ) && IS_LIVE && $errType && defined( 'ERROR_EMAIL' ) ) {
$messageBody = $errType. " [#$errno]: $errstr \n in $errfile on line $errline\n\n". bit_error_string( array( 'errno'=> $errno, 'db_msg'=> $errType ) ). vc( $_SERVER, FALSE );
mail( ERROR_EMAIL, 'PHP '. $errType. ' on '. php_uname( 'n' ). ': '. $errstr, $messageBody );
// Execute PHP's internal error handler
if( $error && $error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_USER_ERROR) ){
header( "HTTP/1.0 500 Internal Server Error" );
print "Internal Server Error";
bit_error_handler( $error['type'], $error['message'], $error['file'], $error['line'] );
// You can prevent sending of error emails by adding define('ERROR_EMAIL', ''); in your config/kernel/config_inc.php
$errorEmail = defined( 'ERROR_EMAIL' ) ? ERROR_EMAIL : (!empty( $_SERVER['SERVER_ADMIN'] ) ? $_SERVER['SERVER_ADMIN'] : NULL);
if( ( !defined( 'IS_LIVE' ) || !IS_LIVE ) ) {
print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>bitweaver - White Screen of Death</title>
<body style="background:#fff; font-family:monospace;">';
// print "<h1>Upgrade Beta 1 to Beta 2</h1>If you are getting this error because you just upgraded your bitweaver from Beta 1 to Beta 2, please follow this link to the installer, which will guide you through the upgrade process: <a href='".BIT_ROOT_URL."install/install.php?step=4'>Upgrade Beta 1 to Beta 2</a>";
print "<h1 style=\"color:#900; font-weight:bold;\">You are running bitweaver in TEST mode</h1>\n";
<li><a href='http://sourceforge.net/tracker/?func=add&group_id=141358&atid=749176'>Click here to log a bug</a>, if this appears to be an error with the application.</li>
<li><a href='". BIT_ROOT_URL. "install/install.php'>Go here to begin the installation process</a>, if you haven't done so already.</li>
<li>To hide this message, please <strong>set the IS_LIVE constant to TRUE</strong> in your config/kernel/config_inc.php file.</li>
print "<pre>". $pLogMessage. "</pre>";
} elseif( $errorEmail ) {
mail( $errorEmail, "$pSubject", $pLogMessage );
if( defined( 'AUTO_BUG_SUBMIT' ) && AUTO_BUG_SUBMIT && !empty( $gBitSystem ) && $gBitSystem->isDatabaseValid() ) {
mail( 'bugs@bitweaver.org',"$pSubject",$pLogMessage );
$date = date("D M d H:i:s Y"); // [Tue Sep 24 12:19:20 2002] [error]
if( isset ( $gBitUser->mInfo ) ) {
$acctStr = "ID: ". $gBitUser->mInfo['user_id']. " - Login: ". $gBitUser->mInfo['login']. " - e-mail: ". $gBitUser->mInfo['email'];
$acctStr = "User unknown";
$info .= $indent. "-----------------------------------------------------------------------------------------------". $separator;
$info .= $indent. "#### USER AGENT: ". $_SERVER['HTTP_USER_AGENT']. $separator;
$info .= $indent. "#### ACCT: ". $acctStr. $separator;
if( !empty( $_SERVER['SCRIPT_URI'] ) ) {
$uri = $_SERVER['SCRIPT_URI']. (!empty($_SERVER['QUERY_STRING'])? '?'. $_SERVER['QUERY_STRING']: ''). $separator;
} elseif( !empty( $argv ) ) {
$info .= $indent. "#### URL: ". $uri;
if( isset ($_SERVER['HTTP_REFERER'] ) ) {
$info .= $indent. "#### REFERRER: $_SERVER[HTTP_REFERER]". $separator;
$info .= $indent. "#### HOST: $_SERVER[HTTP_HOST]". $separator;
$info .= $indent. "#### IP: $_SERVER[REMOTE_ADDR]". $separator;
if( !empty( $gBitDb ) ) {
$info .= $indent. "#### DB: ". $gBitDb->mDb->databaseType. '://'. $gBitDb->mDb->user. '@'. $gBitDb->mDb->host. '/'. $gBitDb->mDb->database. $separator;
if( $gBitDb && isset ( $php_errormsg ) ) {
$info .= $indent. "#### PHP: ". $php_errormsg. $separator;
if ( !empty( $iDBParms['sql'] ) ) {
$badSpace = array("\n", "\t");
$info .= $indent. "#### SQL: ". str_replace($badSpace, ' ', $iDBParms['sql']). $separator;
$info .= $indent. '['. implode( ', ', $iDBParms['p2'] ). ']'. $separator;
$errno = (!empty( $iDBParms['errno'] ) ? 'Errno: '. $iDBParms['errno'] : '');
if( !empty( $iDBParms['db_msg'] ) ) {
$info .= $indent. "#### ERROR CODE: ". $errno. " Message: ". $iDBParms['db_msg'];
$stackTrace = bt( 9999, FALSE );
//multiline expressions matched
if( preg_match_all( "/.*adodb_error_handler\([^\}]*\)(.+\}.+)/ms", $stackTrace, $match )) {
$stackTrace = $match[1][0];
foreach( $globalVars as $global => $hash ) {
$parameters .= $separator. $separator. $global. ': '. $separator. var_export( $hash, TRUE );
$parameters = preg_replace( "/\n/", $separator. $indent, $parameters );
$ret = $info. $separator. $separator. $stackTrace. $parameters;
if (!function_exists('bt')) { // Make sure another backtrace function does not exist
function bt( $levels= 9999, $iPrint= TRUE ) {
if (PHPVERSION() >= 4.3) {
foreach ($traceArr as $arr) {
for ($i= 0; $i <= $tabs; $i++ ) {
if ( isset ($arr['class']) ) {
$sClass .= $arr['class']. '::';
if ( isset ($arr['args']) ) {
foreach( $arr['args'] as $v ) {
} elseif (is_bool($v)) { $args[] = $v ? 'true' : 'false';
if (strlen($v) > $MAXSTRLEN) $str .= '...';
$s .= "\n ". $indent. ' -> ';
$s .= $sClass. $arr['function']. '('. implode(', ',$args). ')';
$s .= @sprintf(" LINE: %4d, %s", $arr['line'],$arr['file']);
print '<pre>'. $s. "</pre>\n";
} // End if function_exists('bt')
// variable argument var dump
// var dump variable in something nicely readable in web browser
function vd( $pVar, $pGlobals= FALSE, $pDelay= FALSE ) {
print '<h2>$_FILES</h2>';
if( !empty( $_COOKIE )) {
print '<h2>$_COOKIE</h2>';
// var capture variable in something nicely readable in web browser
function vc( $iVar, $pHtml= TRUE ) {
if( isset ( $iVar->mDb ) ) {
ini_set( 'xdebug.overload_var_dump', FALSE );
} elseif( $pHtml && !empty( $_SERVER['HTTP_USER_AGENT'] ) && $_SERVER['HTTP_USER_AGENT'] != 'cron' && ((is_object( $iVar ) && !empty( $iVar )) || is_array( $iVar )) ) {
new dBug( $iVar, "", FALSE );
} elseif( is_string( $iVar ) && !empty( $_SERVER['HTTP_USER_AGENT'] ) && $_SERVER['HTTP_USER_AGENT'] != 'cron' ) {
echo "<div><span style='background-color:black;color:white;padding:.5ex;font-weight:bold;'>Var Anatomy</div>";
echo "<div style='border:1px solid black;padding:2ex;background-color:#efe6d6;'>$dbg</div>";
* bitdebug display an debug output when $gDebug is set to TRUE
* @param array $pMessage Message to display
* @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
echo "<pre>$pMessage</pre>";
|