Problem:
Seeing blank white screens in your pages, you know that there are errors in those pages. May be you don’t want to enable error reporting option by .htaccess or by php.ini file, as these both options will show errors in the pages that have errors. You’re just looking for way to display errors in a single script.
Solution:
To display errors in a particular php script, you need to add few codes at the top of it. Please follow the steps below-
Step 1: Enable error displaying option
At first, add the following two lines to enable errors to display-
ini_set(‘display_errors’,1); ini_set(‘display_startup_errors’,1); |
ini_set() function temporary sets a value of a configuration option in the script. In the first line above, this function sets the value 1 to the configuration option “display_errors” which will enable errors to display.
To display the startup sequence errors, add the second line. Note, the first line can’t handle these errors.
Step 2: Decide which errors to display
To display all type of errors, add the following line-
error_reporting(-1); |
errror_reporting function sets which PHP errors to display on the browser. The value -1 is used to display all types of errors.
All-in-one
So, add the following lines in the top of your PHP script where you like to display error messages-
ini_set(‘display_errors’,1); ini_set(‘display_startup_errors’,1); error_reporting(-1); |