PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Error.class.php

https://bitbucket.org/kljungkvist/test-fork
PHP | 73 lines | 46 code | 7 blank | 20 comment | 3 complexity | 8c0f632f708db7b353b02fd12ab87c6c MD5 | raw file
  1. <?php
  2. /*****************************************************
  3. * Error.class.php -- Error handling class
  4. *
  5. * Created by Kristian Ljungkvist 07/10/2002
  6. * KLH 2005/08/19 (changed email address for error notification, commented out the echo)
  7. * KLH 2005/09/27 (changed name of error log file, turned off logging)
  8. * KLH 2005/10/24 (turned on logging for this Engineering version of the file)
  9. *
  10. *****************************************************/
  11. // we will do our own error handling
  12. error_reporting(0);
  13. set_error_handler("userErrorHandler");
  14. // user defined error handling function
  15. function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars)
  16. {
  17. // timestamp for the error entry
  18. $dt = date("Y-m-d H:i:s (T)");
  19. // define an assoc array of error string
  20. // in reality the only entries we should
  21. // consider are 2,8,256,512 and 1024
  22. $errortype = array (
  23. 1 => "Error",
  24. 2 => "Warning",
  25. 4 => "Parsing Error",
  26. 8 => "Notice",
  27. 16 => "Core Error",
  28. 32 => "Core Warning",
  29. 64 => "Compile Error",
  30. 128 => "Compile Warning",
  31. 256 => "User Error",
  32. 512 => "User Warning",
  33. 1024=> "User Notice"
  34. );
  35. // set of errors for which a var trace will be saved
  36. $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
  37. $err = 'Script generating error: ' . $_SERVER['PHP_SELF'] .".\n";
  38. $err .= 'Server Address: ' . $_SERVER['SERVER_ADDR'] . ".\n";
  39. $err .= 'Query String: ' . $_SERVER['QUERY_STRING']. ".\n";
  40. $err .= 'Request from address: ' . $_SERVER['REMOTE_ADDR'] . ".\n";
  41. $err .= 'Client User-Agent: "' . $_SERVER['HTTP_USER_AGENT'] . "\".\n";
  42. $err .= 'Referrer string: "' . $_SERVER['HTTP_REFERER'] . "\".\n\n";
  43. $err .= 'IndividualID from Cookie: ' . $_COOKIE["iid"] ."\n";
  44. $err .= 'TeamID from Cookie: ' . $_COOKIE["tid"] ."\n";
  45. $err .= "<errorentry>\n";
  46. $err .= "\t<datetime>".$dt."</datetime>\n";
  47. $err .= "\t<errornum>".$errno."</errornum>\n";
  48. $err .= "\t<errortype>".$errortype[$errno]."</errortype>\n";
  49. $err .= "\t<errormsg>".$errmsg."</errormsg>\n";
  50. $err .= "\t<scriptname>".$filename."</scriptname>\n";
  51. $err .= "\t<scriptlinenum>".$linenum."</scriptlinenum>\n";
  52. //echo $err;
  53. if (in_array($errno, $user_errors))
  54. $err .= "\t<vartrace>".wddx_serialize_value($vars,"Variables")."</vartrace>\n";
  55. $err .= "</errorentry>\n\n";
  56. // save to the error log, and e-mail me if there is a critical user error
  57. //error_log($err, 3, "errors_engr.log");
  58. if ($errno == E_USER_ERROR) {
  59. mail("ken@sciencebuddies.org","Critical User Error",$err);
  60. mail("kristian.ljungkvist@gmail.com","Critical User Error",$err);
  61. echo '<html><head><META name="ROBOTS" content="NOINDEX,NOFOLLOW"></head><body><p><h1>Announcement</h1></p><p>Our site is currently experiencing high traffic volume. We apologize for the inconvenience. Please check back later.</p><p>-- The Science Buddies Staff</p></body></html>';
  62. // echo "<html><body><p>Our site is currently experiencing high traffic volume. We apologize for the inconvenience. Please check back later.</p><p>The Science Buddies Staff</p></body></html>";
  63. die;
  64. }
  65. }
  66. ?>