I have a PHP script that needs to make responses with http response codes, like HTTP 200 OK, or some 4XX or 5XX code.
How can I do this in PHP?
I have a PHP script that needs to make responses with http response codes, like HTTP 200 OK, or some 4XX or 5XX code.
How can I do this in PHP?
With the header function. There is an example in the section on the first parameter it takes.
Add this line before any output of the body, in the event you aren't using output buffering.
header("HTTP/1.1 200 OK");
Replace the message portion ('OK') with the appropriate message, and the status code with your code as appropriate (404, 501, etc)