PHP custom error page -


ok, so. says "enabling errors shown" in active site bad (due security issues).

now, have consider 2 cases:

  1. the site in debug mode
  2. the site not in debug mode

now, case #1:

we want see errors. how? well:

ini_set('error_reporting', e_all); ini_set('display_errors', 1); 

nothing more simple. can customize error handler errors except parse , fatal.

instead, if case #2:

we able deactivate messages:

ini_set('error_reporting', 0); ini_set('display_errors', 0); 

and it's ok. showing users friendly message such "hei man, f**ked up. don't assure working fix it, since lazy.". should enable errors again , use function set_error_handler() , hope no parse or fatal errors occur. first question is:

question 1: possible avoid error reporting , have custom offline page loaded when goes wrong? mean, possible have ini_set('error_reporting', 0); , ini_set('display_errors', 0); , still able tell php load custom error page?

and another:

question 2: developed class power of set_error_handler() logs errors occurred database. in way can keep track of hack attempts , other cool stuff. (and yes, i'm sure db accessible since application shuts down if cannot connect db). worth something?

some time ago created small system redirects error page when fatal error occurs / uncaught exception thrown. possible assumption, every request handled 1 file , ends in file, reaching end of file i'm sure went ok. condition i've set function redirect on error page , registered shutdown function - called @ end of requests. in function check conditions clean shutdown , if hey met, nothing , output flushed browser, otherwise buffer cleaned , header redirecting error page sent.

simplified version of code:

<?php function redirect_on_error(){     if(!defined('everything_went_ok')){         ob_end_clean();         header('location: error.html');     } }  register_shutdown_function('redirect_on_error');  ob_start();  include 'some/working/code.php';  echo "now i'm going call undefined function or throw bad";  undefined_function(); throw new exception('in case undefined function defined.');      define('everything_went_ok', true); exit; 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -