獲取PHP警告錯誤信息的解決方法
更新時間:2013年06月03日 16:20:49 作者:
本篇文章是對獲取PHP警告錯誤信息的方法進行了詳細(xì)的分析介紹,需要的朋友參考下
代碼如下所示:
<?php
/**
* 更新非法字符、發(fā)送錯誤信息
*
* @author
* @copyright 2009-06-10
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_error_handler('displayErrorHandler');//自定義錯誤
//調(diào)試信息
echo "time:".date("Y-m-d H:i:s")."\n";
//數(shù)據(jù)配置
//公共函數(shù)
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";//調(diào)試顯示
//發(fā)送信息
if($error==1||$error==2) {
sendBankMsg($error_string); //發(fā)送簡訊
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);//去除重復(fù)
$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);
//創(chuàng)建socket連接
$domain = "www.admin.com"; //socket域名
$actionPath = "/action/bank/bankmsg.php"; //文件路徑
$fp = fsockopen($domain,80);
//構(gòu)造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";
//發(fā)送post的數(shù)據(jù)
fputs($fp,$header);
while (!feof($fp)) {
$line = fgets($fp,1024); //去除請求包的頭只顯示頁面的返回數(shù)據(jù)
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;
}
?>
復(fù)制代碼 代碼如下:
<?php
/**
* 更新非法字符、發(fā)送錯誤信息
*
* @author
* @copyright 2009-06-10
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_error_handler('displayErrorHandler');//自定義錯誤
//調(diào)試信息
echo "time:".date("Y-m-d H:i:s")."\n";
//數(shù)據(jù)配置
//公共函數(shù)
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";//調(diào)試顯示
//發(fā)送信息
if($error==1||$error==2) {
sendBankMsg($error_string); //發(fā)送簡訊
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);//去除重復(fù)
$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);
//創(chuàng)建socket連接
$domain = "www.admin.com"; //socket域名
$actionPath = "/action/bank/bankmsg.php"; //文件路徑
$fp = fsockopen($domain,80);
//構(gòu)造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";
//發(fā)送post的數(shù)據(jù)
fputs($fp,$header);
while (!feof($fp)) {
$line = fgets($fp,1024); //去除請求包的頭只顯示頁面的返回數(shù)據(jù)
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;
}
?>
相關(guān)文章
smarty自定義函數(shù)htmlcheckboxes用法實例
這篇文章主要介紹了smarty自定義函數(shù)htmlcheckboxes用法,實例分析了smarty模板與函數(shù)的使用技巧,需要的朋友可以參考下2015-01-01
gd庫圖片下載類實現(xiàn)下載網(wǎng)頁所有圖片的php代碼
在前期的php教程就講了php gd庫可以實現(xiàn)遠(yuǎn)程圖片的下載,但是那只是下載了一張圖片,原理是一樣的,要想下載一個網(wǎng)頁的所有圖片只要使用正則表達(dá)式進行判斷,找出所有的圖片url就可以進行循環(huán)下載了,我特地參照網(wǎng)絡(luò)資源編寫了gd庫圖片下載類!2012-08-08
關(guān)于php微信訂閱號開發(fā)之token驗證后自動發(fā)送消息給訂閱號但是沒有消息返回的問題
最近做了個項目,當(dāng)token驗證之后,發(fā)送消息給訂閱號,但是沒有消息返回,下面小編通過本篇文章給大家分享我的解決辦法2015-12-12
Laravel 默認(rèn)郵箱登錄改成用戶名登錄的實現(xiàn)方法
Laravel中默認(rèn)的登錄是通過郵箱和密碼進行登錄的。那么,怎么樣才能用最少的改動將它改成用密碼登錄呢?下面腳本之家小編給大家?guī)砹薒aravel 默認(rèn)郵箱登錄改成用戶名登錄的實現(xiàn)方法,需要的朋友一起看看吧2019-08-08

