HTTP vastuse staatuse tagastamine PHP-s
Saab eraldi määrata HTTP vastuse staatuse,
ilma et määraksite algusrida.
See tehakse funktsiooni abil
http_response_code:
<?php
http_response_code(404);
?>
Lõpetage kood nii, et antakse edasi vastavad HTTP staatused:
<?php
$arr = ['a', 'b', 'c'];
if (isset($_GET['key'])) {
$key = $_GET['key'];
if (isset($arr[$key])) {
echo $arr[$key];
} else {
// anna 404
echo 'Not Found';
}
} else {
// anna 403
echo 'Forbidden';
}
?>