- Web templates
- E-commerce Templates
- CMS & Blog Templates
- Facebook Templates
- Website Builders
error reporting
September 11, 2015
Once you have installed your template and began working with it, you will inevitably come upon errors from time to time. Although the developers do their best to code error checking and error messages into the code, some errors are not code related. These other errors may be due to server settings or the hosting environment.
Many times the screen may go white or simply something will not look right on the screen. When this happens, the first thing you want to do is to enable the error reporting ability. This allows you to see the specific error messages on the screen.
The web server access and error logs do not always provide sufficient information to determine the source of a PHP error. Luckily, PHP provides excellent error reporting/handling options, you just have to enable them to take advantage. You may use the following examples of enabling error reporting.
There are two ways to enable error reporting in your PHP scripts:
- You can add the following function in the .php file for which you would like the error reporting to be enabled:
error_reporting(E_ALL);
- You can add the following option in the php.ini file for your web site:
error_reporting = E_ALL
Those will enable reporting for all PHP errors. The detailed error_report documentation and various options you can set can be found in the official PHP documentation.
Also, you may use .htaccess directives.
To log PHP errors for the "example.com" website, add the following lines to the .htaccess file in your "web root" folder:
# suppress PHP errors from displaying in the browser php_flag display_startup_errors off php_flag display_errors off php_flag html_errors off
# log PHP errors to a file php_flag log_errors on php_value error_reporting 32767 php_value error_log "/path/to/file"
You can access the log file wherever you configured it to be written. In the example above, the file can be accessed at /path/to/file. Each error will be reported on a new line and each line will be timestamped.