code.fastix.org

Dateiansicht:

Datei:Projekte -> PHP:libError404 -> libError404.php
md5:c4eea2cb1eb4b1491ddc677860344bf6
sha1:247d1057486730b9c2fb32f4f21cf349f392d3f1
  1. <?php
  2. /**
  3. * This scpript can call directly or access as include and executed as a function.
  4. * This script will send a standarded error 404 (Not found) an is nice for real or faked 404-errors
  5. *
  6. * Args:
  7. * 1. string  $logentry  - if false (zero, null, 0 ...) nothing will be logged
  8. *                       - if true this will be logged as a notice
  9. *
  10. * 2. boolean $exit      - if true php will stopped after show the error
  11. *                       - if false php will stopped after show the error
  12. *
  13. * If you  have heders send this will die with a error.
  14. * If you using a ob-buffer he will be claered. It's a good idea to use the ob-buffers if you want to fake the Error 404.
  15. **/
  16.  
  17.  
  18. $error404calledDirect = ( $_SERVER['SCRIPT_FILENAME'] == __FILE__ );
  19.  
  20. if ( $error404calledDirect ) { error404('directly called', true); }
  21.  
  22. function error404($logentry=false, $exit=true) {
  23.     if ( headers_sent() ) {
  24.         trigger_error('Es kann kein Status 404 gesendet werden, weil zuvor Daten gesendet wurden.', E_USER_ERROR);
  25.     } else {
  26.         ob_end_clean();
  27.         header("HTTP/1.0 404 Not Found");
  28. ?>
  29. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
  30. <html><head>
  31. <title>404 Not Found</title>
  32. </head><body>
  33. <h1>Not Found</h1>
  34. <p>The requested URL <?=htmlspecialchars(urldecode($_SERVER['REQUEST_URI']))?> was not found on this server.</p>
  35. <hr>
  36. <address><?=$_SERVER['SERVER_SOFTWARE']?> Server at <?=htmlspecialchars($_SERVER['HTTP_HOST'])?> Port <?=htmlspecialchars($_SERVER['SERVER_PORT'])?></address>
  37. </body></html>
  38. <?php
  39.     }
  40.     if ($logentry) {
  41.         error_log($logentry);
  42.     }
  43.     if ( $exit ) {
  44.         exit;
  45.     } else {
  46.         return true;
  47.     }
  48. }
  49.