如何更改php应用程序中的内部服务器错误代码


how to change Internal server error code in an php application?

在我的PHP应用程序中,每当发生内部服务器或500错误时,我都希望将错误代码从500更改为302。我指的是错误代码302。

尝试使用http_response_code。另外,看看相关问题如何在任何错误时返回http 500代码,无论发生什么。

我不建议您这样做。

相反,将生成此错误的代码包装在Try&Catch语句并尝试在那里处理异常。

try {
   // your code here
} catch (Exception $e) {
   echo $e->getMessage();
}