通过Email发送PHP错误的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了通过Email发送PHP错误的方法。分享给大家供大家参考。具体实现方法如下:

<?php
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
  $email = "
    <p>An error ($number) occurred on line
    <strong>$line</strong> and in the <strong>file: $file.</strong>
    <p> $message </p>";
  $email .= "<pre>" . print_r($vars, 1) . "</pre>";
  $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  // Email the error to someone...
  error_log($email, 1, 'you@youremail.com', $headers);
  // Make sure that you decide how to respond to errors (on the user's side)
  // Either echo an error message, or kill the entire project. Up to you...
  // The code below ensures that we only "die" if the error was more than
  // just a NOTICE.
  if ( ($number !== E_NOTICE) && ($number < 2048) ) {
    die("There was an error. Please try again later.");
  }
}
// We should use our custom function to handle errors.
set_error_handler('nettuts_error_handler');
// Trigger an error... (var doesn't exist)
echo $somevarthatdoesnotexist;

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP取整数函数常用的四种方法小结

ceil — 进一法取整 说明 float ceil ( float value ) 返回不小于 value 的下一个整数,value 如果有小数部分则进一位。ceil() 返回的类型仍...

php addslashes及其他清除空格的方法是不安全的

清除空格的方法是不安全的,部分原因是因为字符中的空格非常多,例如 "addslashes的问题在 于黑客 可以用0xbf27来代替单引号,而addslashes只是将0xbf27修改为0...

基于Windows下Apache PHP5.3.1安装教程

都是下载最新的推荐版本,原来并没想到发到坛子来,所以并没有截图,后来总结到记事本的时候发现还是有蛮多问题的,所以就共享出来,希望对大家 有所帮助。在做实验的时候,我也参考了坛子里其他的前...

PHP实现清除wordpress里恶意代码

公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。 恶意代码示例 复制代码 代码如下: <?...

PHP迭代器接口Iterator用法分析

本文实例讲述了PHP迭代器接口Iterator用法。分享给大家供大家参考,具体如下: PHP Iterator接口的作用是允许对象以自己的方式迭代内部的数据,从而使它可以被循环访问,It...