Returning HTTP Response Status in PHP
You can set the HTTP response status separately,
without specifying the start line.
This is done using the function
http_response_code
:
<?php
http_response_code(404);
?>
Complete the code so that it returns the corresponding HTTP statuses:
<?php
$arr = ['a', 'b', 'c'];
if (isset($_GET['key'])) {
$key = $_GET['key'];
if (isset($arr[$key])) {
echo $arr[$key];
} else {
// return 404
echo 'Not Found';
}
} else {
// return 403
echo 'Forbidden';
}
?>