问题
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