By: Tom Muck
Page 1 of 1
If you are a PHP developer, you are likely familiar with the blank page—an error page with no error message. PHP has some default settings that prevent any error messages from appearing when you install PHP and do not adjust the error display settings. This article will show how to display your error messages.
To display your default settings for php.ini, you can put this code on a blank page and browse to it:
<?php phpinfo();?>
You should see the error settings like this:

Figure 1: PHP settings in php.ini
These are the descriptions of the settings from the php.ini file:
; - display_errors = Off [Security]
; With this directive set to off, errors that occur during the execution of
; scripts will no longer be displayed as a part of the script output, and thus,
; will no longer be exposed to remote users. With some errors, the error message
; content may expose information about your script, web server, or database
; server that may be exploitable for hacking. Production sites should have this
; directive set to off.
; - log_errors = On [Security]
; This directive complements the above one. Any errors that occur during the
; execution of your script will be logged (typically, to your server's error log,
; but can be configured in several ways). Along with setting display_errors to off,
; this setup gives you the ability to fully understand what may have gone wrong,
; without exposing any sensitive information to remote users.
; - error_reporting = E_ALL [Code Cleanliness, Security(?)]
; By default, PHP suppresses errors of type E_NOTICE. These error messages
; are emitted for non-critical errors, but that could be a symptom of a bigger
; problem. Most notably, this will cause error messages about the use
; of uninitialized variables to be displayed.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; error_reporting is a bit-field. Or each number up to get desired error
; reporting level
; E_ALL - All errors and warnings (doesn't include E_STRICT)
; E_ERROR - fatal run-time errors
; E_RECOVERABLE_ERROR - almost fatal run-time errors
; E_WARNING - run-time warnings (non-fatal errors)
; E_PARSE - compile-time parse errors
; E_NOTICE - run-time notices (these are warnings which often result
; from a bug in your code, but it's possible that it was
; intentional (e.g., using an uninitialized variable and
; relying on the fact it's automatically initialized to an
; empty string)
; E_STRICT - run-time notices, enable to have PHP suggest changes
; to your code which will ensure the best interoperability
; and forward compatibility of your code
; E_CORE_ERROR - fatal errors that occur during PHP's initial startup
; E_CORE_WARNING - warnings (non-fatal errors) that occur during PHP's
; initial startup
; E_COMPILE_ERROR - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR - user-generated error message
; E_USER_WARNING - user-generated warning message
; E_USER_NOTICE - user-generated notice message
For a live site, you will likely want the error settings to be left at the default, however, for development it is imperative that you can see your error messages. If you have access to your php.ini file, you can make sure your error display is turned on:
display_errors = On
You will likely want to set your error_reporting to E_ALL, although using E_STRICT will also allow you to make sure you don't have any deprecated code in your files:
error_reporting = E_ALL
If you are working on a remote host, however, you may not have access to this configuration file. On an Apache web server, you can set up an .htaccess file and include this line in the file to turn on error display:
php_flag display_errors on
For a more fine-tuned approach to debug a single script, you can set the php.ini settings programmatically in your script using the ini_set() function. Simply insert this code in your script at the top before any of your PHP code:
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
If you are using an auto-prepend file or a file like application.php (described in this article), you can insert the code at the top of that file.
With the code in place, you can now browse to the problem file and you should be able to see the actual error messages that are being generated.
Conclusion
Debugging PHP is not easy if you cannot see what is happening. By default, errors do not display any indication of what is happening. Making sure you can see your error messages is an important first step in debugging your scripts.
Page 1 of 1 1

Downloads are disabled during your trial period.
Keywords
php,error,debug,debugging,display_errors,blank,page


