How to change HTTP response and show an error message when exception happens in destructor?

不羁的心 提交于 2019-12-13 17:50:24

问题


I have a situation where a PHP function attempts to redirect the browser via an HTTP 302, but an exception is being thrown in a destructor called upon 'exit'ing. The actual code in question is the _doRedirect() method of SimpleSAML but here's a simplified situation:

header('Location: http://somewhere.com', TRUE, 302);
exit; // end script execution

The 'exit' is triggering a destructor for an unrelated class and the error details are getting written out to the HTTP response... but no human notices the error because the browser executes the HTTP 302 redirect.

Ideally I'd like to change the status code to HTTP 500 so the browser would just render the page with the error on it. But is that possible? If not, what options do I have?

来源:https://stackoverflow.com/questions/26186963/how-to-change-http-response-and-show-an-error-message-when-exception-happens-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!