Why is my PHP page blank?
Short answer
A blank page almost always means PHP hit a fatal error and display_errors is off. Turn it on while developing, or read the Apache error log.
Add this to the very top of the file, above everything else:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);Reload. The blank page becomes an error message with a file and line number.
#If it is still blank
The error happened before your ini_set ran — usually a parse error, since PHP compiles the whole file before executing a single line. Check the log instead:
- XAMPP:
xampp/apache/logs/error.log - Linux:
/var/log/apache2/error.logor/var/log/php_errors.log
Or check syntax without running it:
php -l yourfile.php#The usual culprits
- A missing semicolon or unbalanced brace — parse error.
- Calling an undefined function, often a misspelling or a missing extension.
- Exhausting
memory_limiton a big loop or a large file read. - Hitting
max_execution_timeon an unbounded loop.