HTTP cavab statusunun PHP-də qaytarılması
HTTP cavabının statusunu ayrıca,
başlanğıc sətri göstərmədən təyin etmək olar.
Bu, http_response_code funksiyası
vasitəsilə edilir:
<?php
http_response_code(404);
?>
Kodu elə əlavə edin ki, uyğun HTTP statusları qaytarılsın:
<?php
$arr = ['a', 'b', 'c'];
if (isset($_GET['key'])) {
$key = $_GET['key'];
if (isset($arr[$key])) {
echo $arr[$key];
} else {
// 404 qaytar
echo 'Not Found';
}
} else {
// 403 qaytar
echo 'Forbidden';
}
?>