views:

21

answers:

2

Hi. This is the main part of my errorhandler:

function my_error_handler($errno, $errstr, $errfile, $errline){
    $errno = $errno & error_reporting();
    if($errno == 0) return;
    if(!defined('E_STRICT'))            define('E_STRICT', 2048);
    if(!defined('E_RECOVERABLE_ERROR')) define('E_RECOVERABLE_ERROR', 4096);

    $error = ""; 

    switch($errno){
        case E_ERROR:               $error = $error."Error";                  break;
        case E_WARNING:             $error = $error."Warning";                break;
        case E_PARSE:               $error = $error. "Parse Error";            break;
        case E_NOTICE:              $error = $error. "Notice";                 break;
        case E_CORE_ERROR:          $error = $error. "Core Error";             break;
        case E_CORE_WARNING:        $error = $error. "Core Warning";           break;
        case E_COMPILE_ERROR:       $error = $error. "Compile Error";          break;
        case E_COMPILE_WARNING:     $error = $error. "Compile Warning";        break;
        case E_USER_ERROR:          $error = $error. "User Error";             break;
        case E_USER_WARNING:        $error = $error. "User Warning";           break;
        case E_USER_NOTICE:         $error = $error. "User Notice";            break;
        case E_STRICT:              $error = $error. "Strict Notice";          break;
        case E_RECOVERABLE_ERROR:   $error = $error. "Recoverable Error";      break;
        default:                    $error = $error. "Unknown error ($errno)"; break;
    }
    $error = " <i>$errstr</i> in <b>$errfile</b> on line <b>$errline</b><br /> \n";
    $gi = geoip_open("GeoIP/GeoLiteCity.dat",GEOIP_STANDARD);

    $ip = ip(); 

    $user = $_SESSION["username"];  

    $country = geoip_country_name_by_name($gi, $ip);    

    $error .= "User: <b>".$user."</b> Country: <b>".$country."</b> Ip: <b>".$ip."</b> <br /><br /> \n"; 

    //Bruk ip function og kanskje geoip isteden?

    echo "<p>Something went wrong. It has been logged and will be fixed shortly. Thanks </p>";  
    //echo $error; 

    log_error_ereg($error);

    }

This works fine normally, but if i get a critical error it shows it shows php filename, what went wrong etc. Stuff I want to hide from the user. How do I include this type of errors in my error handler? Seems my error handler doesn't pick does up..

+1  A: 

Your error handler needs to return true - if it returns false, the php default error handler will carry on once yours is done.

Also, set display_errors to false:

ini_set('display_errors', false);
adam
+1  A: 

From the PHP manual for set_error_handler:

The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.

mellowsoon