温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PHP 错误处理机制

发布时间:2020-07-11 12:27:19 来源:网络 阅读:418 作者:在特北 栏目:web开发

      

<!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);
		
	}
	
?>

运行示例

PHP 错误处理机制

PHP 错误处理机制


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI