11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 8 • ERROR AND EXCEPTION HANDLINGIgnoring Errors Originating from the Same LocationEnabling ignore_repeated_source causes <strong>PHP</strong> to disregard repeated error messages emanating fromdifferent files or different lines within the same file.Storing Most Recent Error in a VariableEnabling track_errors causes <strong>PHP</strong> to store the most recent error message in the variable $php_errormsg.Once registered, you can do as you please with the variable data, including output it, save it to adatabase, or do any other task suiting a variable.Error LoggingIf you’ve decided to log your errors to a separate text file, the Web server process owner must haveadequate permissions to write to this file. In addition, be sure to place this file outside of the documentroot to lessen the likelihood that an attacker could happen across it and potentially uncover someinformation that is useful for surreptitiously entering your server.You have the option of setting the error_log directive to the operating system’s logging facility(syslog on Linux, Event Viewer on Windows), which will result in <strong>PHP</strong>’s error messages being written tothe operating system’s logging facility or to a text file. When you write to the syslog, the error messageslook like this:Dec 5 10:56:37 example.com httpd: <strong>PHP</strong> Warning:fopen(/home/www/htdocs/subscribers.txt): failed to open stream: Permissiondenied in /home/www/htdocs/book/8/displayerrors.php on line 3When you write to a separate text file, the error messages look like this:[05-Dec-2005 10:53:47] <strong>PHP</strong> Warning:fopen(/home/www/htdocs/subscribers.txt): failed to open stream: Permissiondenied in /home/www/htdocs/book/8/displayerrors.php on line 3As to which one to use, that is a decision that you should make on a per-environment basis. If yourWeb site is running on a shared server, using a separate text file or database table is probably your onlysolution. If you control the server, using the syslog may be ideal because you’d be able to take advantageof a syslog-parsing utility to review and analyze the logs. Take care to examine both routes and choosethe strategy that best fits the configuration of your server environment.<strong>PHP</strong> enables you to send custom messages as well as general error output to the system syslog. Fourfunctions facilitate this feature. These functions are introduced in the next section, followed by aconcluding example.179

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!