Trigger 500 Internal Server Error in PHP and display Apache error page

前端 未结 9 1091
一整个雨季
一整个雨季 2020-12-25 11:30

How can i trigger 500 Internal Server Error or 404 Page Not Found Apache errors in PHP?

For 500 Internal Server Error i have tried

9条回答
  •  青春惊慌失措
    2020-12-25 12:14

    you simply cannot trigger apache error pages from php code without hackery redirection as proposed by ben lee because error document redirection is handled by another layer of your application's stack (specifically, apache's mod_core).
    when your script runs, it's too late.

    the trickery of getting an error page by throwing an exception heavily depends on your php.ini's settings about error handling and verbosity.

    http_response_code()currently only exists in php's svn thus it's not available in most production environments which are supposed to run an official release version.

    my advice is to properly implement a custom error and exception handler via set_error_handler() and set_exception_handler(), respectively, use header() to send the client proper http status information and (if needed) generate error pages.

提交回复
热议问题