Web Development with PHP, HTML, CSS, & JavaScript

Showing all errors with PHP

Friday 22nd January 2010

When developing a site with PHP, it can be a great testing tool to be able to see any errors resulting from your code. Sometimes the default server php configuration hides these errors and in my experience most of them do. But you can show the errors with a couple of extra lines of code. This allows you to see where you've gone wrong (and why things aren't doing what you think they should), whether it be due to variables not initialised or of the wrong type, or from a mysql error. Just place the following two lines at the top of your php script:

ini_set('display_errors', '1');

This code allows you to see error notices and warnings. Even if your site appears to be working correctly, you could have a number of warnings from inefficient code or due to forgetfulness. You do have to be vigilant though, and make sure that error displaying is turned off when your website is "live." Although a great tool in the development process, on a live site error messaging can be a very valuable source of information for people looking to attaack your site. The messages may seem like a different language to the regular user, but a maliciuous developer could force errors on a site in an attempt to identify possible weaknesses and areas to attack.

Filed under: