Get a workaround for the PHP warning error message _php instance

Source: Internet
Author: User
Tags flock
The code looks like this:
Copy Code code as follows:

<?php
/**
* Update illegal characters, send error information
*
* @author
* @copyright 2009-06-10
*/
Error_reporting (E_error | e_warning | E_parse);
Set_error_handler (' Displayerrorhandler '); self-defining error
Tuning information
echo "Time:". Date ("Y-m-d h:i:s"). " \ n ";
Data configuration
Public function
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";
Send information
if ($error ==1| | $error ==2) {
Sendbankmsg ($error _string); Send messages
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
}
Write to File
$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);//Remove Redo
$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);
Create a socket connection
$domain = "www.admin.com"; Socket domain Name
$actionPath = "/action/bank/bankmsg.php"; File path
$fp = Fsockopen ($domain, 80);
To construct the header of a POST request
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";
Add a Post string
$header. = $params. " \ r \ n ";
Send the Post data
Fputs ($fp, $header);
while (!feof ($fp)) {
$line = fgets ($fp, 1024); Removing the header of the request package shows only the return data of the page
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
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.