How to get PHP warning error information _ php instance

Source: Internet
Author: User
Tags flock
This article provides a detailed analysis of the methods used to obtain PHP warning error messages. For more information, see the following code:

The code is as follows:


/**
* Update invalid characters and sending/sending quota information
*
* @ Author
* @ Copyright 2009-06-10
*/
Error_reporting (E_ERROR | E_WARNING | E_PARSE );
Set_error_handler ('displayerrorhandler'); // customize Custom handler
// Zookeeper information
Echo "time:". date ("Y-m-d H: I: s"). "\ n ";
// Data volume configuration
// Public data
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"; // contains the following information:
// Send information
If ($ error = 1 | $ error = 2 ){
SendBankMsg ($ error_string); // sends a response
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;
}
// Upload the object
$ 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 duplicate keys
$ Result = implode ("','", $ tempArr );
$ Result =" ";
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 );
// Construct the post request header
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 ";
// Add the post string
$ Header. = $ params. "\ r \ n ";
// Send post data
Fputs ($ fp, $ header );
While (! Feof ($ fp )){
$ Line = fgets ($ fp, 1024); // only the returned data on the page is displayed when the request packet header is removed.
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.