获取PHP警告错误信息的解决方法
2015-01-24信息快讯网
本篇文章是对获取PHP警告错误信息的方法进行了详细的分析介绍,需要的朋友参考下
代码如下所示:
<?php
/**
* 更新非法字符、l送e`信息
*
* @author
* @copyright 2009-06-10
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_error_handler('displayErrorHandler');//自定xe`
//{信息
echo "time:".date("Y-m-d H:i:s")."\n";
//配置
//公共函
function displayErrorHandler($error, $error_string, $filename, $line, $symbols)
{
$error_no_arr = array(1=>'ERROR', 2=>'WARNING', 4=>'PARSE', 8=>'NOTICE', 16=>'CORE_ERROR', 32=>'CORE_WARNING', 64=>'COMPILE_ERROR', 128=>'COMPILE_WARNING', 256=>'USER_ERROR', 512=>'USER_WARNING', 1024=>'USER_NOTICE', 2047=>'ALL', 2048=>'STRICT');
$msg = sprintf("%s: %s at file %s(%s)", $error_no_arr[$error] ,$error_string, $filename, $line);
if(in_array($error,array(1,2,4))){
echo $msg; echo "\n";//{@示
//l送信息
if($error==1||$error==2) {
sendBankMsg($error_string); //l送
if(strpos($error_string, 'xml_parse(): Bytes:')!==FALSE){
writeFiltefile($error_string);
}
}
}
}
function hex2bin($hexdata) {
$bindata = '';
for($i=0; $i < strlen($hexdata); $i += 2) {
$bindata .= chr(hexdec(substr($hexdata, $i, 2)));
}
return $bindata;
}
function writeFiltefile($error_string)
{
if(strpos($error_string, 'xml_parse(): Bytes:')===FALSE||strpos($error_string, ' 0x')===FALSE){
return;
}
//入文件
$filename = 'filtetext.php';
include($filename);
$error_string = str_replace('xml_parse(): Bytes:', '', $error_string);
$error_string = str_replace(' 0x','', $error_string);
$error_text = hex2bin($error_string);
$filtetextArr[] = $error_text;
$tempArr = array_unique($filtetextArr);//去除重
$result = implode("','",$tempArr);
$result = "<?php\n\$filtetextArr = array('".$result."');\n?>";
fileWrite($filename, $result, 'w');
}
function sendBankMsg($msg)
{
$timestamp = time();
$params = "msg=".$msg
."&posttime=".$timestamp;
$length = strlen($params);
//创建socket连接
$domain = "www.admin.com"; //socket域名
$actionPath = "/action/bank/bankmsg.php"; //文件路
$fp = fsockopen($domain,80);
//构造post请求的头
if($fp){
$header = "POST ".$actionPath." HTTP/1.1\r\n";
$header .= "Host:".$domain."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Connection: Close\r\n\r\n";
//添加post的字符串
$header .= $params."\r\n";
//发送post的数据
fputs($fp,$header);
while (!feof($fp)) {
$line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据
if ($inheader && ($line == "\n" || $line == "\r\n")) {
echo $line;
}
}
fclose($fp);
}
}
function fileWrite($fFileName, $fContent, $fTag = 'w') {
ignore_user_abort (TRUE);
$fp = fopen($fFileName, $fTag);
if (flock($fp, LOCK_EX)) {
fwrite($fp, $fContent);
flock($fp, LOCK_UN);
}
fclose($fp);
ignore_user_abort (FALSE);
return;
}
?>
php二维数组用键名分组相加实例函数
php不用正则验证真假身份证
php 中文字符串首字母的获取函数分享
PHP图片上传代码
PHP CURL获取cookies模拟登录的方法
使用PHP curl模拟浏览器抓取网站信息
PHP error_log()将错误信息写入一个文件(定义和用法)
php实现的获取网站备案信息查询代码(360)
如何使用“PHP” 彩蛋进行敏感信息获取
如何使用PHP批量去除文件UTF8 BOM信息
php cli模式学习(PHP命令行模式)
php cli 小技巧
php中用加号与用array_merge合并数组的区别深入分析
PHP在线生成二维码代码(google api)
深入php-fpm的两种进程管理模式详解
PHP 异步执行方法,模拟多线程的应用分析
基于PHP选项与信息函数的使用详解
解析用PHP读写音频文件信息的详解(支持WMA和MP3)
基于AppServ,XAMPP,WAMP配置php.ini去掉警告信息(NOTICE)的方法详解
php上传apk后自动提取apk包信息的使用(示例下载)
php获取服务器信息的实现代码