/funkce.php/debug.fce.php

https://github.com/GE3/GE3 · PHP · 110 lines · 80 code · 16 blank · 14 comment · 0 complexity · ac2f6671000c4840ed760063bc89e970 MD5 · raw file

  1. <?php
  2. /* -- Nastavení logování chyb na email -- */
  3. function myErrorHandler($errno, $errstr, $errfile, $errline){
  4. /* Poznámky
  5. Uživatelské chyby lze uměle vyvolat – trigger_error().
  6. set_error_handler() – nastaví callback funkci, která se použije pro ošetření libovolné chyby v PHP
  7. debug_backtrace() vrací aktuální stav PHP zásobníku.
  8. error_log() posílá zprávu do logovacího systému. Logovací systém může zprávu zapsat do logu web. serveru, poslat zprávu přes TCP spojení, přes email, nebo ji zapsat do souboru.
  9. */
  10. // Nastavení
  11. $cfgLog = True;
  12. $cfgMail = False;
  13. $cfgEcho = True;
  14. $errortype = array (E_ERROR => 'Error',
  15. E_WARNING => 'Warning',
  16. E_PARSE => 'Parsing Error',
  17. E_NOTICE => 'Notice',
  18. E_CORE_ERROR => 'Core Error',
  19. E_CORE_WARNING => 'Core Warning',
  20. E_COMPILE_ERROR => 'Compile Error',
  21. E_COMPILE_WARNING => 'Compile Warning',
  22. E_USER_ERROR => 'User Error',
  23. E_USER_WARNING => 'User Warning',
  24. E_USER_NOTICE => 'User Notice',
  25. E_STRICT => 'Runtime Notice',
  26. E_RECOVERABLE_ERROR => 'Catchable Fatal Error');
  27. // Zapsání do logu
  28. If( $cfgLog ){
  29. $errorText = '<span style="color: #666666; font-size: 8pt;">'.date("j.n.Y G:i")." &raquo;</span> <b>".$errortype[$errno].":</b> $errstr in <b>$errfile</b> on line $errline. ";
  30. If( file_exists("_errlog.html") AND is_writable("_errlog.html") ){
  31. $log = @file_get_contents("_errlog.html");
  32. $os = fopen("_errlog.html", "w");
  33. }
  34. If( file_exists("../_errlog.html") AND is_writable("../_errlog.html") ){
  35. $log = @file_get_contents("../_errlog.html");
  36. $os = fopen("../_errlog.html", "w");
  37. }
  38. fwrite($os, $errorText."<br>&nbsp;<br> \r\n\r\n".$log);
  39. fclose($os);
  40. }
  41. // Odeslání emailu
  42. If( $cfgMail ){
  43. $errorText = $errortype[$errno].": $errstr in $errfile on line $errline. ";
  44. odesliChybu($errorText);
  45. }
  46. // Zobrazení chyby
  47. If( $cfgEcho ){
  48. $errorText = "<b>".$errortype[$errno].":</b> $errstr in <b>$errfile</b> on line $errline. ";
  49. Echo "<p>» $errorText<br>";
  50. If($cfgMail) Echo "Údaje o chybě byly zaslány našim technikům a budeme ji co nejdříve řešit. Omlouváme se za potíže. <br>&nbsp;";
  51. }
  52. Return True;
  53. }
  54. //set_error_handler("myErrorHandler", error_reporting());
  55. Function bugReport($text){ #dříve odesliChybu()
  56. /* -- Config -- */
  57. $emailAdr = "";
  58. /* -- Function body -- */
  59. $errorText = "Na stránce $_SERVER[HTTP_HOST]"."$_SERVER[REQUEST_URI] se vyskytla chyba: \n$text \n";
  60. $errorText.= "\n \n-- Výpis GET hodnot --\n";
  61. Foreach($_GET as $key=>$value){
  62. If( is_array($value) )
  63. Foreach($value as $key2=>$value2) $errorText.= "$key»$key2: '$value2'\n";
  64. Else $errorText.= "$key: '$value'\n";
  65. }
  66. $errorText.= "\n \n-- Výpis POST hodnot --\n";
  67. Foreach($_POST as $key=>$value){
  68. If( is_array($value) )
  69. Foreach($value as $key2=>$value2) $errorText.= "$key»$key2: '$value2'\n";
  70. Else $errorText.= "$key: '$value'\n";
  71. }
  72. $errorText.= "\n \n-- Výpis COOKIE hodnot --\n";
  73. Foreach($_COOKIE as $key=>$value){
  74. If( is_array($value) )
  75. Foreach($value as $key2=>$value2) $errorText.= "$key»$key2: '$value2'\n";
  76. Else $errorText.= "$key: '$value'\n";
  77. }
  78. $errorText.= "\n \n-- Výpis SESSION hodnot --\n";
  79. Foreach($_SESSION as $key=>$value){
  80. If( is_array($value) )
  81. Foreach($value as $key2=>$value2) $errorText.= "$key»$key2: '$value2'\n";
  82. Else $errorText.= "$key: '$value'\n";
  83. }
  84. If( mail($emailAdr, "Automaticke hlaseni chyby PHP", $errorText, "Content-Type: text/plain; charset=utf-8\r\n") )
  85. Return True;
  86. Else Return False;
  87. }
  88. Function textareaPrint_r($values, $nazev=''){
  89. Echo '<textarea rows="6" cols="80">';
  90. If($nazev) Echo "$nazev = ";
  91. print_r($values);
  92. Echo '</textarea>';
  93. }
  94. ?>