views:

34

answers:

2

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?

+2  A: 

With the header function. There is an example in the section on the first parameter it takes.

David Dorward
+1  A: 

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)

sparkey0
Thank you very much!
Paulocoghi
You're welcome!
sparkey0