如何正确注销?

How to make correct logout?

我通过 post 方法注销并将响应重定向到主页,但是要获取主页的 html 我需要使用 get 方法。

我应该如何正确地从 post 重定向到 get? 或者有没有更合适的登出方法?

我为此使用 Slim v3 框架,它不允许从一种方法重定向到另一种方法。

$app->get('/', function (Request $request, Response $response) {
    return $this->renderer->render($response, 'index.phtml');
});

$app->post('/logout', function (Request $request, Response $response) {
    return $this->model->logout($response)->withRedirect("/", 308);
});

据我所知,通过 POST 方法注销并通过 GET 获取 html 页面是最佳做法。

使用响应代码 302 它将自动使用 GET.

308保留请求方法。参见 https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/308

302 Found 这样的非缓存重定向在你的情况下也更可取,而不是像 301/[ 这样的永久重定向=17=]308.