Jump to content

HTTP response code


cbreemer
Go to solution Solved by mac_gyver,

Recommended Posts

Hi Freaks, 
I am using XMLHttpRequest in my JavaScript code to execute PHP scripts on the server. Works great but one thing puzzles me.

Whenever my PHP code triggers a runtime exception (such as a mandatory parameter being empty), the request returns with HTTP status 200 OK.
Same happens even when there is a syntax error in my PHP code. Why does it not return a 500 Internal Server error in these cases ?
Is there a way to get that behavior without having to check each and every command and explicitly setting a 500 status ?

Thanks for any ideas !

Edited by cbreemer
typo
Link to comment
Share on other sites

  • Solution

to get php to cause a http 500 status for fatal syntax/runtime errors, php's display_errors setting needs to be set to OFF. you would then want the log_errors setting to be set to ON, so that you have a record of what errors are occurring. also, php's error_reporting needs to always be set to E_ALL or a -1.

Link to comment
Share on other sites

Thanks for that @mac_gyver ! I now remember seeing these tips posted before so I should probably have known.
I can't get that to work just now but I'm sure I am doing it wrong and it looks like I first need to study the various error/logging functions in some depth.

Meanwhile I'm quite satisfied with my hack, which relies on the observation (fact ?) that PHP error output always starts with <br />
It's a kludge, I know, but for a private hobby project it looks good enough until proven different.
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.