I need your help for a PHP script. How do I respond with an appropriate HTTP status: 2xx for success, 4xx for bad request (no retry), or 5xx server unavailable (retry) from a specified url?
With http_response_code:
<?php
http_response_code(404);
?>
Send the header before any output is sent:
below PHP 5.4
header("HTTP/1.0 404 Not Found");
header("HTTP/1.1 200 OK");
header("HTTP/1.1 500 Internal Server Error");
PHP 5.4 and above
http_response_code(404);
http_response_code(200);
http_response_code(500);
More about sending HTTP headers with PHP: http://php.net/manual/en/function.header.php
An overview of the available header response codes: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html