PHP.nl

http_response_code

http_response_code

Get or Set the HTTP response code

 **http_response_code** int $response_code

Gets or sets the HTTP response status code.

response_code The optional will set the response code. response_code

If is provided, then the previous status code will be returned. If is not provided, then the current status code will be returned. Both of these values will default to a status code if used in a web server environment. response_code``response_code``200

false will be returned if is not provided and it is not invoked in a web server environment (such as from a CLI application). true will be returned if is provided and it is not invoked in a web server environment (but only when no previous response status has been set). response_code``response_code

Voorbeeld: Using in a web server environment

<?php

// Get the current response code and set a new one
var_dump(http_response_code(404));

// Get the new response code
var_dump(http_response_code());
?>
int(200)
int(404)

Voorbeeld: Using in a CLI environment

<?php

// Get the current default response code
var_dump(http_response_code());

// Set a response code
var_dump(http_response_code(201));

// Get the new response code
var_dump(http_response_code());
?>
bool(false)
bool(true)
int(201)

header``headers_list