HTTP atbildes statusa atdošana PHP
Var atsevišķi iestatīt HTTP atbildes statusu,
nenorādot sākuma rindu.
Tas tiek darīts, izmantojot funkciju
http_response_code:
<?php
http_response_code(404);
?>
Pabeidziet kodu tā, lai tiktu atdoti atbilstošie HTTP statusi:
<?php
$arr = ['a', 'b', 'c'];
if (isset($_GET['key'])) {
$key = $_GET['key'];
if (isset($arr[$key])) {
echo $arr[$key];
} else {
// atdot 404
echo 'Not Found';
}
} else {
// atdot 403
echo 'Forbidden';
}
?>