Open thinsoldier opened 7 years ago
I use this:
$klein->onHttpError(function ($code, $router) {
if ($code == 404) {
$service = $router->service();
$service->render('views/404.php');
}
});
It returns a 404 response header.
@Spirit55555 I changed my code to exactly match yours and it definitely is still giving me 200 OK.
To get 404 I had to force headers to be sent.
$klein->onHttpError(function ($code, $router) {
if ($code == 404) {
$router->response()->sendHeaders( true, true);
$service = $router->service();
$service->render('views/404.php');
}
});
That is strange, it works without forcing the headers here.
As far as I can tell, this issue appeared for me after updating php version. Then I had to force the headers as well.
https://github.com/klein/klein.php/wiki/Handling-404's
The suggested technique in the wiki only shows how to send a few lines of text when 404 errors happen. I can't figure out how to server a fully styled document for 404. I mean I can serve a full document but then the http header changes from 404 to 200.