Ignore:
Timestamp:
Sep 5, 2008, 3:24:01 AM (16 years ago)
Author:
rvelices
Message:
  • better management of fatal errors (instead of die or trigger_error rather use fatal_error ...)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_html.inc.php

    r2488 r2502  
    651651}
    652652
     653/**
     654 * exits the current script with 500 http code
     655 * this method can be called at any time (does not use template/language/user etc...)
     656 * @param string msg a message to display
     657 */
     658function fatal_error($msg)
     659{
     660  $btrace_msg = '';
     661  if (function_exists('debug_backtrace'))
     662  {
     663    $bt = debug_backtrace();
     664    for ($i=1; $i<count($bt); $i++)
     665    {
     666      $class = isset($bt[$i]['class']) ? (@$bt[$i]['class'].'::') : '';
     667      $btrace_msg .= "#$i\t".$class.@$bt[$i]['function'].' '.@$bt[$i]['file']."(".@$bt[$i]['line'].")\n";
     668    }
     669    $btrace_msg = trim($btrace_msg);
     670    $msg .= "\n";
     671  }
     672
     673  $display = "<h1>Piwigo encountered a non recoverable error</h1>
     674<pre style='font-size:larger;background:white;color:red;padding:1em;margin:0;clear:both;display:block;width:auto;height:auto;overflow:auto'>
     675<b>$msg</b>
     676$btrace_msg
     677</pre>\n";
     678
     679  @set_status_header(500);
     680  echo $display.str_repeat( ' ', 300); //IE doesn't error output if below a size
     681
     682  if ( function_exists('ini_set') )
     683  {// if possible turn off error display (we display it)
     684    ini_set('display_errors', false);
     685  }
     686  error_reporting( E_ALL );
     687  trigger_error( strip_tags($msg).$btrace_msg, E_USER_ERROR );
     688  die(0); // just in case
     689}
     690
    653691/* returns the title to be displayed above thumbnails on tag page
    654692 */
Note: See TracChangeset for help on using the changeset viewer.