PHP errors and exceptions notes and Summary (5) options related to error logs in the configuration file

Source: Internet
Author: User
Tags stack trace system log

"Record error (production environment)"

Ini:

① turn on/off error log function

Log_errors = On

② Setting the maximum number of bytes for log_errors

1024

Other:

Options Describe
Log_errors Sets whether to log error messages to logs or Error_log
Error_log Set the file to which the script error will be logged
Log_errors_max_len Set the maximum number of bytes for log_errors
Ignore_repeated_errors Whether to ignore duplicate error messages
Ignore_repeated_source Whether to ignore the source of duplicate error messages
Track_errors If this option is turned on, the last error will be permanently saved in $php_errormsg

"Method One" logs the error to the specified file

① Open the log_errors in php.ini

② specifies the path to save the error log, for example:

" D:/wamp/logs/php_error.log "

"Example 1"

<?PHP//Turn off error displayIni_set ('display_errors',0);//Show All ErrorsError_reporting (-1);//Log Errors//error at notification levelecho $test;//WarningSettype ($var,'Dee');//Fatal errorTest ();

The page will not have any output. Open D:\wamp\logs\php_error.log:

[ +-may- -  the: -: -UTC] PHPNotice: Undefined variable:testinchD:\practise\php\Error\error1.php on line9[ +-may- -  the: -: -UTC] PHP Stack trace:[ +-may- -  the: -: -UTC] PHP1. {main} () D:\practise\php\Error\error1.php:0[ +-may- -  the: -: -UTC] PHPWarning: Settype () [<a href='Function.settype'>function.settype</a>]: Invalid typeinchD:\practise\php\Error\error1.php on line One[ +-may- -  the: -: -UTC] PHP Stack trace:[ +-may- -  the: -: -UTC] PHP1. {main} () D:\practise\php\Error\error1.php:0[ +-may- -  the: -: -UTC] PHP2. Settype () D:\practise\php\Error\error1.php: One[ +-may- -  the: -: -UTC] PHPFatal Error: Call to undefined function test ()inchD:\practise\php\Error\error1.php on line -[ +-may- -  the: -: -UTC] PHP Stack trace:[ +-may- -  the: -: -UTC] PHP1. {main} () D:\practise\php\Error\error1.php:0

Example 2 sets the path to the Save error log in Ini_set ().

<?PHP//Turn off error displayIni_set(' Display_errors ', 0);//setting the path to the error logIni_set(' Error_log ', ' D:\wamp\logs\php_error_2.log ');//Show All Errorserror_reporting(-1);//Error logging error//notification levelEcho $test; //WarningSettype($var, ' Dee ');//Fatal errorTest ();

The page will not have any output. Open D:\wamp\logs\php_error_2.log:

[19-may-2015 16:04:41 UTC] PhpNotice: Undefined variable:test in D:\practise\php\Error\error1.php on line 11[19-may-2015 16:04:41 UTC] PHP Stack Trace:[19-may-2015 16:04:41 UTC] PHP 1. {main} () d:\practise\php\error\error1.php:0[19-may-2015 16:04:41 UTC] PHPWarning:Settype() [<a href= ' Function.settype ' >function.Settype</a>]: Invalid type in D:\practise\php\Error\error1.php on line 13[19-may-2015 16:04:41 UTC] PHP Stack Trace:[19-may-2015 16:04:41 UTC] PHP 1. {main} () d:\practise\php\error\error1.php:0[19-may-2015 16:04:41 UTC] PHP 2.Settype() d:\practise\php\error\error1.php:13[19-may-2015 16:04:41 UTC] PHPFatal Error: Call to undefinedfunctionTest () in D:\practise\php\Error\error1.php on line 15[19-may-2015 16:04:41 UTC] PHP Stack Trace:[19-may-2015 16:04:41 UTC] PHP 1. {main} () d:\practise\php\error\error1.php:0

"Example 3" records when the user attempts to log on to the system with what password time and IP address (for example, through the log analysis of the water injection robot)

Login.html

<!DOCTYPE HTML><HTML>    <Head>        <title>TODO supply a title</title>        <MetaCharSet= "UTF-8">        <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0">    </Head>    <Body>        <H1>Login</H1>        <formAction= "doaction.php"Method= "POST">User name:<inputtype= "text"name= "username" /><BR/>Password:<inputtype= "Password"name= "Password" /><BR/>            <inputtype= "Submit"value= "Login">        </form>    </Body></HTML>

doaction.php:

<?PHP//do not show all errorsIni_set(' Display_errors ', 0);//Error Level: All Errorserror_reporting(-1);//turn on the error log functionIni_set(' Log_errors ', ' on ');//Set error log save pathIni_set(' Error_log ', ' D:\wamp\logs\login.log ');//Ignore duplicate error messagesIni_set(' Ignore_repeated_errors ', ' on ');//ignore the source of duplicate messagesIni_set(' Ignore_repeated_source ', ' on ');//Setting the time zoneIni_set(' Date.timezone ', ' PRC ');$username=$_post[' username '];$password=$_post[' Password '];if($username= = ' Admin ' &&$password= = ' Admin '){    Echo' Login Chen Gong ';}Else{    //the time and IP address when the administrator attempts to log on to the system with what password    $date=Date("Y-m-d h:i:s", Time()); $ip=$_server[' REMOTE_ADDR ']; $message= "User {$usernameIn$dateTo$passwordTry to log on to the system, the current user's IP address is {$ip}"; Error_log($message); //Jump    Header(' location:login.html ');}

Open: D:\wamp\logs\login.log:

[19-may-2015 16:25:59 UTC] User Dee at 2015-05-20 00:25:59 with Dee trying to log on to the system, the current user's IP address is 127.0.0.1

"Method Two" logs the error to the system log

"Method Three " sends an error as a message

PHP errors and exceptions notes and Summary (5) options related to error logs in the configuration file

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.