Why is my PHP page blank?
If a PHP page is entirely blank, it almost certainly means there is an error in your PHP code, and that the display_errors directive in your web server is turned off. Most hosting companies these days turn off display_errors as a security measure, because error messages can reveal vulnerabilities to a malicious attacker. However, you should always test PHP pages first in a safe development environment on your local computer or network.
In a local testing environment, the display_errors directive should be turned on. If you have used an all-in-one package to install PHP/MySQL, the package's control panel might have an option to turn on the display of errors. If not, you need to edit php.ini, the configuration file that is normally located in the main PHP folder.
Scroll down to the Error handling and logging section. For a development environment, you should use the following settings:
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
;http://php.net/error-reporting
error_reporting = E_ALL | E_STRICT
; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; It's recommended that errors be logged on production servers rather than
; having the errors sent to STDOUT.
; Possible Values:
; Off = Do not display any errors
; stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
; On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
;http://php.net/display-errors
display_errors = On
This extract from php.ini is taken from the version in PHP 5.3. Your version of php.ini might look slightly different, but the values for the directives should be the same.
After saving php.ini, restart your web server for the changes to take effect.
Turning on the display of errors temporarily on a live server
Sometimes, you might need to turn on the display of errors temporarily if something goes wrong with a script on your remote server. Add the following code at the very top of the script:
When you reload the page, this should display any error message. When you have fixed the problem, remove this line of code.
NOTE: this technique does not work if your page contains a syntax (parse) error, such as a missing semicolon, or an unmatched quote or parenthesis. It is, however, useful for displaying warning about missing include files.