Posted By

cochambre on 06/30/06


Tagged

parse mail error handler send administrator notify


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

mate
nicolaspar
oso96_2000
willcodeforfood


Intercepta los errores de ejecución y los envía por mail al administrador con detalle del contexto


 / Published in: PHP
 

  1. function error_handler($errno, $errstr, $errfile, $errline, $errctx) {
  2.  
  3. $EN_DESARROLLO = (substr_count($_SERVER['HTTP_HOST'],"localhost")==0)? false : true;
  4.  
  5. $host = $_SERVER['HTTP_HOST'];
  6. $mail_subject = 'Error at '.$host;
  7. $mail_from = '[email protected]';
  8. $mail_to = array('[email protected]','[email protected]');
  9.  
  10. $errortype = array(1=>"Error", 2=>"Warning", 4=>"Parsing Error", 8=>"Notice", 16=>"Core Error", 32=>"Core Warning", 64=>"Compile Error", 128=>"Compile Warning", 256=>"User Error", 512=>"User Warning", 1024=>"User Notice", 2048=>"PHP5 Strict Notice");
  11.  
  12. $error_handler_string = "<font size=2 face=Arial><h3>Error at ".$host."<br></h3><b>Date: </b>".date('F j, Y, H:i:s a')."<br><b>Error Type: </b>". $errortype[$errno]." (".$errno.")<br><b>Description: <font color=ff0000>".$errstr."</font></b><br><b>Error File: </b>".$errfile."<br><b>Error Line: </b>".$errline."<br><br>";
  13.  
  14. while( isset($_SESSION) && list($var, $val) = each($_SESSION) ) $error_handler_string .= "_SESSION[".$var."] = ".$val."<BR>";
  15. while( isset($_GET) && list($var, $val) = each($_GET) ) $error_handler_string .= "_GET[".$var."] = ".$val."<BR>";
  16. while( isset($_POST) && list($var, $val) = each($_POST) ) $error_handler_string .= "_POST[".$var."] = ".$val."<BR>";
  17. while( isset($_COOKIE) && list($var, $val) = each($_COOKIE) ) $error_handler_string .= "_COOKIE[".$var."] = ".$val."<BR>";
  18.  
  19. if( $EN_DESARROLLO ){
  20. die($error_handler_string);
  21. }else{
  22. @ini_set("sendmail_from",$mail_from);
  23. foreach( $mail_to as $mail_to_str ){
  24. mail($mail_to_str, $mail_subject, $error_handler_string, "From: ".$mail_from."\r\nContent-Type: text/html; charset=\"iso-8859-1\"\r\n");
  25. }
  26. if ($errno & (E_WARNING | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)){
  27. header("Location: http://".$host);
  28. exit();
  29. }
  30. }
  31. }
  32. set_error_handler("error_handler");
  33. ini_set('display_errors','on');

Report this snippet  

You need to login to post a comment.