使用PHP动态捕获服务器错误

时间:2022-06-01 08:41:47

my answer is quite simple: Is there a way to catch server-errors (like Error 400, 401, 403, 404, 500...) automatically with PHP and generate custom Error-Pages.

我的答案很简单:有没有办法用PHP自动捕获服务器错误(如错误400,401,403,404,500 ...)并生成自定义错误页面。

For example, let's say I got a PHP-File with the page and it just inserts the Error-Code and the Error-Message.

例如,假设我有一个带有页面的PHP文件,它只是插入错误代码和错误消息。

Thanks in advance!

提前致谢!

2 个解决方案

#1


1  

You may use custom exception handler function (set_exception_handler()) and error handler (set_error_handler()) for turn errors to Exception (example)

您可以使用自定义异常处理函数(set_exception_handler())和错误处理程序(set_error_handler())将错误转换为异常(示例)

#2


0  

ErrorDocument 404 /404.html

404 here is your error code and /404.html is your redirection file when error occurs. here goes your tutorial.. http://www.totallyphp.co.uk/custom-error-pages-using-htaccess

404这里是您的错误代码,而/404.html是发生错误时的重定向文件。这里是你的教程.. http://www.totallyphp.co.uk/custom-error-pages-using-htaccess

#1


1  

You may use custom exception handler function (set_exception_handler()) and error handler (set_error_handler()) for turn errors to Exception (example)

您可以使用自定义异常处理函数(set_exception_handler())和错误处理程序(set_error_handler())将错误转换为异常(示例)

#2


0  

ErrorDocument 404 /404.html

404 here is your error code and /404.html is your redirection file when error occurs. here goes your tutorial.. http://www.totallyphp.co.uk/custom-error-pages-using-htaccess

404这里是您的错误代码,而/404.html是发生错误时的重定向文件。这里是你的教程.. http://www.totallyphp.co.uk/custom-error-pages-using-htaccess