Changeset 538 for trunk/includes/error.php
- Timestamp:
- May 14, 2013, 9:21:06 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/error.php
r507 r538 1 1 <?php 2 2 3 function EmptyErrorHandler($Number, $Message, $Filename, $LineNumber, $Variables) 4 { 5 } 6 7 function CustomErrorHandler($Number, $Message, $Filename, $LineNumber, $Variables) 3 function Report($Backtrace) 8 4 { 9 5 global $Config; 10 6 11 set_error_handler('EmptyErrorHandler'); 7 $Error = ''; 8 $Date = date('Y-m-d H:i:s'); 9 foreach($Backtrace as $Item) 10 { 11 if(!array_key_exists('line', $Item)) $Item['line'] = ''; 12 if(!array_key_exists('file', $Item)) $Item['file'] = ''; 13 if(!array_key_exists('function', $Item)) $Item['function'] = ''; 14 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 15 $Arguments = ''; 16 if(array_key_exists('args', $Item) and is_array($Item['args'])) 17 foreach($Item['args'] as $Item) 18 { 19 if(is_array($Item)) $Arguments .= "'".serialize($Item)."',"; 20 else $Arguments .= "'".serialize($Item)."',"; 21 } 22 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')'; 23 $Error .= "\n"; 24 } 25 $Error .= "\n"; 26 //if($Config['Web']['ErrorLogFile'] != '') 27 //error_log($Error, 3, $Config['Web']['ErrorLogFile']); 28 // Pošli mi zprávu (pokud je to kritická chyba) 29 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 30 // Show error message 31 if($Config['Web']['ShowPHPError'] == true) 32 { 33 echo('<?xml version="1.0" encoding="utf-8"?>'."\n". 34 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'. 35 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'. 36 '<head>'. 37 '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'. 38 '</head><body>'. 39 'Došlo k vnitřní chybě!<br /> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br /><br />'); 40 echo('<pre>'.$Error.'</pre><br />'); 41 echo('</body></html>'); 42 } 43 WriteLog($Error, LOG_TYPE_ERROR); 44 } 12 45 13 $Date = date('Y-m-d H:i:s'); // časové razítko položky 46 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables) 47 { 48 $UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE; 14 49 $ErrorType = array 15 50 ( … … 26 61 1024 => 'User Notice' 27 62 ); 28 $UserErrors = E_ALL; //E_ERROR | E_WARNING | E_PARSE;29 63 30 64 if(($UserErrors & $Number)) 31 65 { 32 $Error = '# '.$Date.' : '.$Message.' on line '.$LineNumber."\n";33 66 $Backtrace = debug_backtrace(); 34 $Backtrace[0]['function'] = '';67 $Backtrace[0]['function'] = $Message; 35 68 $Backtrace[0]['args'] = ''; 36 //$First = array_shift($Backtrace); 37 //print_r($First); 38 39 //array_unshift($Backtrace, $First); 40 //array_shift($Backtrace); 41 //print_r($Backtrace); 42 foreach($Backtrace as $Item) 43 { 44 //print_r($Item); 45 if(!array_key_exists('line', $Item)) $Item['line'] = ''; 46 if(!array_key_exists('file', $Item)) $Item['file'] = ''; 47 if(!array_key_exists('function', $Item)) $Item['function'] = ''; 48 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 49 $Arguments = ''; 50 if(array_key_exists('args', $Item) and is_array($Item['args'])) 51 foreach($Item['args'] as $Item) 52 { 53 if(is_array($Item)) $Arguments .= "'".serialize($Item)."',"; 54 else $Arguments .= "'".serialize($Item)."',"; 55 } 56 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')'; 57 $Error .= "\n"; 58 59 } 60 $Error .= "\n"; 61 //if($Config['Web']['ErrorLogFile'] != '') 62 //error_log($Error, 3, $Config['Web']['ErrorLogFile']); 63 // Pošli mi zprávu (pokud je to kritická chyba) 64 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 65 // Show error message 66 if($Config['Web']['ShowPHPError'] == true) 67 { 68 echo('<?xml version="1.0" encoding="utf-8"?>'."\n". 69 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'. 70 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'. 71 '<head>'. 72 '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'. 73 '</head><body>'. 74 'Došlo k vnitřní chybě!<br /> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br /><br />'); 75 echo('<pre>'.$Error.'</pre><br />'); // V případě ladění chybu i zobraz 76 echo('</body></html>'); 77 } 78 WriteLog($Error, LOG_TYPE_ERROR); 69 $Backtrace[0]['file'] = $FileName; 70 $Backtrace[0]['line'] = $LineNumber; 71 Report($Backtrace); 79 72 if((E_ERROR | E_PARSE) & $Number) die(); 80 73 } 81 set_error_handler('CustomErrorHandler');82 74 } 83 75 84 //set_error_handler('CustomErrorHandler'); 76 function ExceptionHandler(Exception $Exception) 77 { 78 $Backtrace = $Exception->getTrace(); 79 array_unshift($Backtrace, array( 80 'function' => $Exception->getMessage(), 81 'file' => $Exception->getFile(), 82 'line' => $Exception->getLine(), 83 )); 84 Report($Backtrace); 85 die(); 86 } 85 87 86 88 ?>
Note:
See TracChangeset
for help on using the changeset viewer.