Page 1 of 1

Return 500 Response Code on Parse Errors, not 200

Posted: Sat Sep 06, 2008 4:21 pm
by lightnb
Is it possible to configure PHP to send down a different response code on parse errors?

It seems that the server / php returns 200 "OK", even if there's a parse error. It would seem more appropriate to return a 500 "Internal Server Error", since that's much more accurate.

I know there's a header() function, but that won't work if the script has errors, will it?

Re: Return 500 Response Code on Parse Errors, not 200

Posted: Sat Sep 06, 2008 4:51 pm
by Cut

Code: Select all

 
function errorhandler {
 header('HTTP 500');
 print('500!');
}
 
set_error_handler('errorhandler');
 

Re: Return 500 Response Code on Parse Errors, not 200

Posted: Sat Sep 06, 2008 7:00 pm
by lightnb
Thanks!