[nycphp-talk] Can I set the response code if a PHP Fatal error occurs?
Michael Sims
jellicle at gmail.com
Tue Feb 17 10:52:20 EST 2009
On Tuesday 17 February 2009, lorband at optonline.net wrote:
> I am using AJAX to submit a PHP request. If a PHP Fatal error occurs
> when running the php program, the http response code is 200 and it
> appears the program ran successfully. Is there a way for php to return a
> 500 http response code when a fatal error occurs so myjava_script that is
> processing the response can alert the user that an error has occurred?
> Try/catch won't capture fatal errors for me to set the header. Thank you,
> Lori
Your Javascript code should look like this:
a) did I get the right data back from the server? If so, report success.
b) Otherwise, report failure to the user.
It doesn't matter what went wrong on the server side, if you're just
reporting to the user. MAke your PHP script return something (the word
"good" for example), have your javascript look for that word, if it didn't
get that word, report to the user "Something seems to be wrong".
Behind the scenes it might matter to you what went wrong with the PHP
script, but it doesn't matter to the user at all. You shouldn't be testing
the http status code as a way to figure out if things were successful - test
some data output by the PHP script, where that data is only sent if
everything went correctly.
Michael Sims
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090217/627a3f67/attachment.html>
More information about the talk
mailing list