How to return an HTTP 500 code on any error, no matter what

后端 未结 7 866
无人及你
无人及你 2020-12-09 14:35

I\'m writing an authentication script in PHP, to be called as an API, that needs to return 200only in the case that it approves the request, and403(Forbid

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 15:02

    header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
    

    You should not use 500, that indicates an internal server error.

    This (and other headers) should be sent before any ouput, except if you have output buffering enabled.

提交回复
热议问题