basic-php-09-snippet06.php / php
<?php //create your error handler function function handler(error_message, error_line) { switch(//fatal error case E_ERROR: to = "Administrator <admin@yourdomain.com>"; body = "<html>"; <head>"; body .= "<title>Website error</title>"; </head>"; body .= "<body>"; <h1>Fatal Error</h1>"; body .= "Error received was a <b>" . </b> error.<br>"; body .= "The page that generated the error was: <b>" . </b>"; body .= " and was generated on line: <b>" . </b><br>"; body .= "The generated error message was:" . body .= "</body>"; </html>"; headers = "MIME-Version: 1.0\r\n"; headers .= "From: Apache Error <host@yourdomain.com>\r\n"; to, body, //kill the script break; //warnings case E_WARNING: to = "Administrator <admin@yourdomain.com>"; body = "<html>"; <head>"; body .= "<title></title>"; </head>"; body .= "<body>"; <h1>Warning</h1>"; body .= "Error received was a <b>" . </b> error.<br>"; body .= "The page that generated the error was: <b>" . </b>"; body .= " and was generated on line: <b>" . </b><br>"; body .= "The generated error message was:" . body .= "</body>"; </html>"; headers = "MIME-Version: 1.0\r\n"; headers .= "From: Apache Error <host@yourdomain.com>\r\n"; to, body, //script will continue //notices case E_NOTICE: //don't show notice errors break; } } /* set error handling to 0 we will handle all error reporting only notifying admin on warnings and fatal errors don't bother with notices as they are trivial errors really only meant for debugging */ error_reporting(0); //set the error handler to be used set_error_handler("handler"); /* Create the rest of your page here. We will not be displaying any errors We will be e-mailing the admin an error message Keep in mind that fatal errors will still halt the execution, but they will still notify the admin */ ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.