send http status code php code example

Example: php set http code

/* Example #1 Using http_response_code() in a web server environment
--------------------------------------------------------------------*/
// Get the current response code and set a new one
var_dump(http_response_code(404));  // output: 200
// Get the new response code
var_dump(http_response_code());     // output: 404

/* Example #2 Using http_response_code() in a CLI environment
-------------------------------------------------------------*/
// Get the current default response code
var_dump(http_response_code());     // output: false
// Set a response code
var_dump(http_response_code(201));  // output: true
// Get the new response code
var_dump(http_response_code());     // output: 201

Tags:

Php Example