http-response-codes

PHP: How to send HTTP response code?

扶醉桌前 提交于 2019-11-25 22:45:51
问题 I have a PHP script that needs to make responses with HTTP response codes (status-codes), like HTTP 200 OK, or some 4XX or 5XX code. How can I do this in PHP? 回答1: I just found this question and thought it needs a more comprehensive answer: As of PHP 5.4 there are three methods to accomplish this: Assembling the response code on your own (PHP >= 4.0) The header() function has a special use-case that detects a HTTP response line and lets you replace that with a custom one header("HTTP/1.1 200

403 Forbidden vs 401 Unauthorized HTTP responses

一曲冷凌霜 提交于 2019-11-25 21:57:40
问题 For a web page that exists, but for which a user that does not have sufficient privileges, (they are not logged in or do not belong to the proper user group), what is the proper HTTP response to serve? 401? 403? Something else? What I\'ve read on each so far isn\'t very clear on the difference between the two. What use cases are appropriate for each response? 回答1: A clear explanation from Daniel Irvine: There's a problem with 401 Unauthorized , the HTTP status code for authentication errors.