PHP Exceptions redirected to custom error page -


the functions have written throwing exceptions if can't job. productive environment thought redirect exception nice looking error page. therefore i'm thinking of setting exception handler set_exception_handler on beginning of every script. how error page know error occured? thought of putting error code url header("location: error.php?code=1234"). while in development phase not set exception handler, every exception printed onto php default error screen uncaugt exception: ... usefull informations.

i have read exceptions in php - try/catch or set_exception_handler? don't know how write front controller script , think maybe effort.

i'm php beginner likes handle errors in right way, i'm not sure if i'm doing right or wrong. think it's ok doing above described or have other suggestions?

thank you!

don't redirect. in exception handler function output error page @ point (or include php file includes error page html). want set appropriate status code (using php header function).

edit: why not redirect:

  • you want return appropriate http status code on error pages (usually 404, 403, 400, 500 or 503 depending on cause), search engine robots know not index error, crawlers can identify broken pages, browsers know not cache page , on. if redirect, returning 301/302 http status code , not 1 of error ones.
  • you want users able refresh page error on, in case temporary glitch. if redirect them url, many times refresh see error page (since that's page they're on).

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -