If you’re working with crappy web host, you might notice that you’re getting a lot of blank PHP pages. This is likely due to PHP’s error reporting being completely turned off - you can check this by creating a page called “info.php” and on it, putting:
<?php phpinfo(); ?>
This will output your PHP configuration when viewed in a web browser. Look for the “error_reporting” setting - it is most likely set to “off.” Don’t be too surprised, I’m working with a client that paid good money for a Linux “Developer Package” over at web.com - the trouble is developers sure do rely on error reporting!
Fortunately, there’s a fix. Add this PHP code to the top of your page:
<?php
ini_set ('display_errors', 1);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>
This will print out all warnings except for notices, which is the standard PHP error reporting on most hosts. I tend to put this into an include file that gets included on every page. Let’s say you put this into a master include file that resides inside the “includes” folder, which is in your public document root folder (often called “web” or “html” or “httpdocs”). On your regular pages, you might do something like this:
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/master.php'); ?>
Using the $_SERVER[’DOCUMENT_ROOT’] global variable prevents you from having to guess relative paths all the time. Using this also allows you to move scripts freely from host to host, as you never have to hard-code the doc root into your applications.
Hope that helps someone! Cheers.
Leave a comment