标签:trigger_error() error_log() php错误处理
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Make Error Happen!</title> </head> <body> <form action = "error_.php" method = "post"> <table border ="0"> <tr> <td>MESSAGE:</td> <td><input type="text" maxlength="50" size="30" name="error_msg"/></td> </tr> <tr> <td> <select name="error"> <option value="256"> E_USER_ERROR </option> <option value="512">E_USER_WARNING </option> <option value="1024">E_USER_NOTICE </option>> </select> </td> </tr> <tr> <td colspan = "2" algin = "center"> <input type = "submit" value = "submit error"/> </td> </tr> </table> </form> </body> </html> <?php //错误处理函数 function error_handle($error_level, $error_msg) { echo "an error is cause by user and the error level is:".$error_level."error message is:".$error_msg; //调用error_log函数将错误信息写入日志(以追加形式) error_log(date(‘Y-m-d G-i-s‘).$error_level.$error_msg.‘\n‘,3,‘error_log.txt‘); } //设置错误处理函数,只处理由用户自己引起的错误 set_error_handler("error_handle",E_USER_ERROR|E_USER_NOTICE|E_USER_WARNING); if(isset($_POST[‘error‘]) && isset($_POST[‘error_msg‘])) { $error_level = (int)$_POST[‘error‘]; $error_msg = $_POST[‘error_msg‘]; trigger_error($error_msg,$error_level); } ?>
运行示例
本文出自 “Debug Me” 博客,请务必保留此出处http://zaitebie.blog.51cto.com/11179646/1747700
标签:trigger_error() error_log() php错误处理
原文地址:http://zaitebie.blog.51cto.com/11179646/1747700