通过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后台程序与Javascript的两种交互方式

方法一:通过Cookie交互。 一共是三个文件,分别为:index.htm,action.php,main.htm 原理为前台页面main.htm和后台action.php通过页面框架...

php allow_url_include的应用和解释

因为这个原因,许多安全研究人员建议在php.ini配置中禁用指向allow_url_fopen。不幸的是,许多推荐这种方法的人,并没有意识到,这样会破坏很多的应用并且并不能保证100%的...

php天翼开放平台短信发送接口实现方法

本文实例讲述了php天翼开放平台短信发送接口实现方法。分享给大家供大家参考。具体分析如下: 临时性需求,研究了一下天翼开发平台的东西,用来发送验证码还是不错的,但是每日限额不多,所以很鸡...

php获得url参数中具有&的值的方法

实际在项目过程中,我们经常会遇到要获取上一页地址的路径。你可以返回上一页使用 复制代码 代码如下: <script>window.history.go(-1);</sc...

php strcmp使用说明

以区分大小写的方式比较两个字符串 Strcmp()函数对两个字符串进行二进制安全的比较,并区分大小写。其形式为: int strcmp ( string str1 , string st...