HTTP atbildes sākuma rindas nodošana PHP
Izmantojot funkciju header var
arī nodot HTTP atbildes sākuma rindu.
Parasti to izmanto, lai norādītu statusu.
Galvenokārt 404 kļūdai:
<?php
header('HTTP/1.1 404 Not Found');
?>
Pabeidziet kodu tā, lai tiktu nodots
404 kļūdas galvene:
<?php
$arr = ['a', 'b', 'c'];
$key = $_GET['key'];
if (isset($arr[$key])) {
echo $arr[$key];
} else {
// nodot 404
echo 'error';
}
?>