Return 500 Response Code on Parse Errors, not 200

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lightnb
Forum Newbie
Posts: 13
Joined: Mon Jul 28, 2008 11:13 pm

Return 500 Response Code on Parse Errors, not 200

Post 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?
Cut
Forum Commoner
Posts: 39
Joined: Sat Aug 23, 2008 8:01 pm

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

Post by Cut »

Code: Select all

 
function errorhandler {
 header('HTTP 500');
 print('500!');
}
 
set_error_handler('errorhandler');
 
lightnb
Forum Newbie
Posts: 13
Joined: Mon Jul 28, 2008 11:13 pm

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

Post by lightnb »

Thanks!
Post Reply