Home Backend Development PHP Tutorial 用PHP即?捕捉PHP原始?中的??并?送email通知

用PHP即?捕捉PHP原始?中的??并?送email通知

Jun 23, 2016 pm 02:37 PM

??PHP的朋友都知道,其?最?心的就是程序中出?一些?常或??,?些??如果?出到用?的?幕?把用????,甚至?此?了工作,如果不?出到?幕就得想?法??到日?中,但是似乎不是每?人都有查看??日?的??,?了解????尬的??,所以我?了?段代?,其用意就是?我??的php程式出?的?候把???容捕捉出?然後?到我?的email?.
先看效果:

 

Define('SYS_DEBUG',false);IF(SYS_DEBUG) {ini_set('display_errors','on');Error_reporting(E_ALL);//上?后使用??定Error_reporting(E_ERROR | E_WARNING | E_PARSE);}Else{ini_set('display_errors','off');Error_reporting(0);}//??捕捉Register_shutdown_function('Fun::Error');Class Fun{/**通用出??理参数:要?出的?容,是否?止?行程序?明:有?值??函式可以用??出自定?的???容另外?可以配合Register_shutdown_function??自?抓取???容,??抓取的???容?送到Email?Register_shutdown_function的?制是程序?行完?或中途出???用函?如果是自?抓取???被?用,??取得最後一次出?的?容,如果???有???容?跳出返回:?容?被直接?出至?幕或Email?用法:Fun::Error('???容');Fun::Error('???容',False);/**/Public Static Function Error($M='',$E=True){$ErrTpl='<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><table cellspacing="0" cellpadding="0" border="0"><tr><td style="padding:5px;background-color:#F57900;font-size:13px;border:1px solid #444;color:#222;">{$M}</td></tr></table>';$M=Trim($M);IF($M!='') {//手工?用$M=' <b>注意:</b> '.$M;Echo Strtr($ErrTpl,Array('{$M}'=>$M));unSet($ErrTpl);IF($E===True) {Die();}Return ;}Else{//程式?行完?自?抓取????用$M=error_get_last();//取得最後?生的??IF(!Is_array($M) Or Count($M)<4) {Unset($M);Return ;}IF(!File_Exists($M['file'])) {Unset($M);Return ;}//取得5行出???代?,如果取不到?容,?明出??案不存在$E=Array_slice(File($M['file']),($M['line']-4),5);IF(!Is_array($E)) {Unset($M,$E);Return ;}$E['M']='';For($i=0;$i<5;$i++) {$E[$i]=isSet($E[$i]) ? $E[$i] : '';$E['M'].='  ';$E['M'].=($i==3) ? '<b>'.(($M['line']-3)+($i+1)).'</b>' : (($M['line']-3)+($i+1));$E['M'].=': '.Htmlspecialchars($E[$i],ENT_QUOTES,'UTF-8').'<br>';}$E=&$E['M'];$M='<b>自?捕捉到有???生!</b><br><br><b>??描述:</b><br>  <b>'.$M['file'].'</b>的第<b>'.$M['line'].'</b>行出?了?型?<b>'.$M['type'].'</b>的??:<br>  '.$M['message'].'<br><br><b>??代?:</b><br>'.$E.'<br>'.self::now('Y-m-d H:i:s',time()).'<br>';$M=Strtr($ErrTpl,Array('{$M}'=>$M));unSet($ErrTpl);$G=seft::getG('SYS','config');IF(!self::Mail2($G['Spe'],'警告: '.$G['Tit'].' 出? PHP 程式??!',$M) And SYS_DEBUG===True){throw new Exception('警告: '.$G['Tit'].' 出? PHP 程式??!<br><br>'.$M);}IF(SYS_DEBUG) {Echo $M;}unSet($E,$M,$G);Die();}}/**发送??参数:收件人,?件??(不可有?行符),?件?容(行?行之?必?用\n分隔,每行不可超?70?字符)?明:?用PHP?置函式Mail?送??返回:返回布?值用法:$IsSend=Fun::Mail2($email,$tit,$msg);/**/Public Static Function Mail2($to,$tit,$msg) {IF(Filter_var($to,FILTER_VALIDATE_EMAIL)==''){throw new Exception('??地址??!');}$tit='=?UTF-8?B?'.Base64_Encode($tit).'?=';$msg = str_replace("\n.","\n..",$msg);     //Windows如果在一行开头发现一个句号则会被删掉,要避免此问题将单个句号替换成两个句号Return Mail($to,$tit,$msg,'From:'.seft::getG('config/SYS/Mal')."\n".'Content-Type:text/html;charset=utf-8');}}
Copy after login

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles