Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Error messages in PHP

What do you want to happen if something goes wrong when your PHP script is running? Do you want an error message to appear on the screen automatically? Or would you prefer to handle the error yourself? Or have it logged to a file? How about warnings which, although they're not fatal, could effect the ongoing operation of your script?

And does it matter?

Yes - it DOES matter. When you're developing and testing a script, it's great to have all your errors (and warnings) displayed so that you be altered to problems early on and debug quickly and efficiently. But when your system has been released you really don't want error messages displayed to the user. Not only would they make the user question the reliability of your site, but also they might reveal information about your script ("evidence") that would help a technically knowledgeable user to compromise your security.

WHERE ARE ERROR SETTINGS MADE?

Error settings may be made.

 1. Server wide, in the php.ini or httpd.conf files.
 2. Within individual directories via the .htaccess file.
 3. Within multiple scripts via a common include file.
 4. Within a single script.

Settings made server wide can be overwritten on a per-directory basis, which can then be overridden within scripts - either via include files or directly in the scripts. Examples

1. (for php.ini)

 log_errors = on
 error_log = /var/logs/php/errlog.txt

2. (for use in .htaccess file)

 php_flag log_errors on
 php_value error_log /var/logs/php/errlog.txt

3. and 4. (use this source or similar within your PHP code).

 ini_set('log_errors',1);
 ini_set('error_log','/var/logs/php/errlog.txt');

HOW DO I CHOOSE WHERE ERRORS ARE REPORTED?

The settings involved are

 display_errors to choose whether errors appear on the screen

 log_errors to choose whether errors go to syslog or a file
 error_log to control the destination for log_errors

 track_errors puts the most recent error into $php_errormsg

HOW DO I CHOOSE WHICH ERRORS ARE REPORTED?

The main settings are made through the error_reporting parameter or function which is a bit pattern allowing you to specify about a dozen (slightly more in PHP5) different levels / types you can be told about. For example, to see everything except warnings, notices and comments about bad coding practise, you might set
     E_ALL & ~E_WARNING & ~E_NOTICE & ~E_STRICT
(the latter is PHP5 only, by the way).

You can tune your reporting using parameters such as ignore_repeated_errors and ignore_repeated_source.


See also PHP Best Practice - Module

Please note that articles in this section of our web site were current and correct to the best of our ability when published, but by the nature of our business may go out of date quite quickly. The quoting of a price, contract term or any other information in this area of our website is NOT an offer to supply now on those terms - please check back via our main web site

Related Material

Designing PHP-Based Solutions: Best Practice
  [123] - ()
  [237] - ()
  [261] - ()
  [340] - ()
  [394] - ()
  [426] - ()
  [563] - ()
  [572] - ()
  [839] - ()
  [896] - ()
  [936] - ()
  [945] - ()
  [1047] - ()
  [1052] - ()
  [1166] - ()
  [1181] - ()
  [1182] - ()
  [1194] - ()
  [1321] - ()
  [1323] - ()
  [1381] - ()
  [1389] - ()
  [1390] - ()
  [1391] - ()
  [1482] - ()
  [1487] - ()
  [1490] - ()
  [1533] - ()
  [1623] - ()
  [1694] - ()
  [1794] - ()
  [2199] - ()
  [2221] - ()
  [2430] - ()
  [2679] - ()
  [3539] - ()
  [3813] - ()
  [3820] - ()
  [3926] - ()
  [4069] - ()
  [4118] - ()
  [4326] - ()
  [4641] - ()
  [4691] - ()

Web site techniques, utility and visibility
  [23] - ()
  [32] - ()
  [98] - ()
  [109] - ()
  [117] - ()
  [142] - ()
  [165] - ()
  [173] - ()
  [179] - ()
  [182] - ()
  [197] - ()
  [202] - ()
  [222] - ()
  [259] - ()
  [261] - ()
  [268] - ()
  [274] - ()
  [276] - ()
  [278] - ()
  [284] - ()
  [288] - ()
  [311] - ()
  [314] - ()
  [320] - ()
  [322] - ()
  [347] - ()
  [348] - ()
  [369] - ()
  [376] - ()
  [414] - ()
  [492] - ()
  [510] - ()
  [528] - ()
  [533] - ()
  [649] - ()
  [658] - ()
  [681] - ()
  [718] - ()
  [732] - ()
  [757] - ()
  [767] - ()
  [800] - ()
  [893] - ()
  [916] - ()
  [976] - ()
  [994] - ()
  [1015] - ()
  [1029] - ()
  [1055] - ()
  [1104] - ()
  [1177] - ()
  [1184] - ()
  [1186] - ()
  [1198] - ()
  [1207] - ()
  [1212] - ()
  [1237] - ()
  [1297] - ()
  [1437] - ()
  [1494] - ()
  [1505] - ()
  [1506] - ()
  [1513] - ()
  [1534] - ()
  [1541] - ()
  [1554] - ()
  [1610] - ()
  [1630] - ()
  [1634] - ()
  [1653] - ()
  [1711] - ()
  [1747] - ()
  [1756] - ()
  [1793] - ()
  [1797] - ()
  [1833] - ()
  [1856] - ()
  [1888] - ()
  [1955] - ()
  [1961] - ()
  [1970] - ()
  [1982] - ()
  [2056] - ()
  [2065] - ()
  [2225] - ()
  [2332] - ()
  [2333] - ()
  [2334] - ()
  [2335] - ()
  [2336] - ()
  [2337] - ()
  [2338] - ()
  [2339] - ()
  [2340] - ()
  [2340] - ()
  [2341] - ()
  [2389] - ()
  [2410] - ()
  [2519] - ()
  [2532] - ()
  [2552] - ()
  [2569] - ()
  [2668] - ()
  [2981] - ()
  [3022] - ()
  [3087] - ()
  [3149] - ()
  [3197] - ()
  [3367] - ()
  [3426] - ()
  [3491] - ()
  [3532] - ()
  [3554] - ()
  [3563] - ()
  [3589] - ()
  [3623] - ()
  [3734] - ()
  [3744] - ()
  [3745] - ()
  [3776] - ()
  [3896] - ()
  [3974] - ()
  [4001] - ()
  [4076] - ()
  [4115] - ()
  [4136] - ()
  [4239] - ()
  [4376] - ()
  [4401] - ()
  [4474] - ()
  [4492] - ()

resource index - PHP
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on subjects such as Ruby, Lua, Perl, Python, Linux, C, C++, Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer) many questions, and answers to those which are of general interest are published in this area of our site.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/php-erro ... n-php.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard