Thursday, November 7, 2019
How to Turn on PHP Error Reporting
How to Turn on PHP Error Reporting If you are running into a blank orà white page or some other PHP error, but you have no clue what is wrong, you should consider turning on PHP error reporting. Thisà gives you some indication of where or what the problem is, and it is a good first step to solving any PHP problem. You use the error_reporting function to turn on error reporting for a specific file that you want to receive errors on, or you can enable error reporting for all your files at your web server by editing the php.ini file. This saves you the agony of going over thousands of lines of code looking for an error. Error_reporting Function The error_reporting() functionà establishes the error reporting criteriaà at runtime. Because PHP has several levels of reportable errors, this function sets the desired level for the duration of your script. Include the function early in the script, usually immediately after the opening ?php. You have several choices, some of which are illustrated below: ?php //Report simple run errors error_reporting(E_ERROR | E_WARNING | E_PARSE); //Report E_NOTICE in addition to simple run errors //(to catch uninitialized variables or variable name misspellings) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); //Report all PHP errors error_reporting(-1); //Report all PHP errors (see changelog) error_reporting(E_ALL); //Turn off all error reports error_reporting(0); ? How to DisplayErrors Display_error determines whether errors are printed on the screen or hidden from the user. It is used in conjunction with the error_reporting function as shown in the example below: ini_set(display_errors,1); error_reporting(E_ALL); Changing the php.ini File at the Website To see all error reports for all your files, go to your web server and access the php.ini file for your website. Add the following option: error_reportingE_ALL The php.ini file is the default configuration file for running applications that use PHP. By placing this option in the php.ini file, you are requesting error messages for all your PHP scripts.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.