basic-php-09-error-rev02.php / php
<?php function email_admin(error_output, full_time, to = "Administrator <admin@yourdomain.com>"; body = "<html>"; <head>"; body .= "<title>Apache Error</title>"; </head>"; body .= "<body>"; <b>" . full_date . "</b> " . "at <b>" . </b><br>"; body .= "Error received was a <b>" . </b> error.<br>"; body .= "The page that generated the error was: <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, date = getdate(); date['weekday'] . ", " . date['mday'] . ", " . full_time = date['minutes'] . ":" . date['year']; _SERVER['QUERY_STRING']; _SERVER['REQUEST_URI']; switch (error_output = "<h1>\"Bad Request\" Error Page - " . "(Error Code 400)</h1>"; <br>"; error_output .= "<a href=\"mailto:sysadmin@localhost.com\">;" . "Contact</a> the system administrator"; error_no, full_date, request_page); break; case 401: <h1>\"Authorization Required\" Error Page - " . "(Error Code 401)</h1>"; error_output .= "You have supplied the wrong information to " . "access a secure area<br>"; </a> the system administrator"; error_output .= " if you feel this to be in error"; email_admin(error_output, full_time, error_output = "<h1>\"Forbidden Access\" Error Page - " . "(Error Code 403)</h1>"; <br>"; error_output .= "<a href=\"mailto:sysadmin@localhost.com\">;" . "Contact</a> the system administrator"; error_no, full_date, request_page); break; case 404: <h1>\"Page Not Found\" Error Page - " . "(Error Code 404)</h1>"; error_output .= "The page you are looking for " . "cannot be found<br>"; </a> the system administrator"; error_output .= " if you feel this to be in error"; email_admin(error_output, full_time, error_output = "<h1>\"Internal Server Error\" Error Page - " . "(Error Code 500)</h1>"; <br>"; error_output .= "<a href=\"mailto:sysadmin@localhost.com\">;" . "Contact</a> the system administrator"; error_no, full_date, request_page); break; default: <h1>Error Page</h1>"; error_output .= "This is the custom error Page<br>"; </a>"; } ?> <html> <head> <title>Beginning PHP5, Apache, MySQL Web Development</title> </head> <body> <?php echo error_output; ?> </body> </html>
(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.