PHP category

Auto-saving with jQuery

http://jetlogs.org/2007/11/11/auto-saving-with-jquery/

No Comments

Blank Pages due to PHP Error Reporting being turned off

If you are programming in php and you are getting blank pages you may have PHP’s error reporting  turned off.  This can be checked by creating a page called “phpinfo.php” and on it, putting:

<?php phpinfo(); ?>

The phpinfo function will output your PHP configuration when viewed in a web browser. Search for the term“error_reporting”.  If you are getting blank pages is it mor than likely set to “off.”

This problem can be fixed by turning on error reporting at run-time.  To do this, add the following PHP code to the top of your page:

<?php
ini_set ('display_errors', 1);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
?>

This prints out all warnings except for notices.  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.

No Comments

Turning On PHP Error Reporting

A good way to help you troubleshoot your php code is to use the helpful messages php returns when an error occurs.  To do this, enter the following code.

1
2
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);

No Comments