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

后端 未结 7 867
无人及你
无人及你 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:17

    Since PHP 5.4.0 there is a specialized function:

    
    

    Just make sure that it's called before any other output.

    Reference:

    • https://www.php.net/manual/en/function.http-response-code.php

提交回复
热议问题