<!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);
}
?>
运行示例
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。