记住我的工作方式就好像 always_remember_me 设置为 true

Remember me works as if always_remember_me is set to true

我尝试在 Symfony 5 中设置记住我的功能。 当复选框未被选中并登录时,用户在重新打开浏览器后仍然处于连接状态。

这是我的配置 (security.yaml) :

security:
#(...)
    firewalls:
#(...)
        main:
#(...)
            remember_me:
                secret:   '%kernel.secret%'
                lifetime: 31536000 # 365 days in seconds (default)
                path:     /
                # by default, the feature is enabled by checking a
                # checkbox in the login form (see below), uncomment the
                # following line to always enable it.
                #always_remember_me: true

            form_login:
                login_path: login
                check_path: login
                use_referer: true
                default_target_path: welcome_locale
#(...)

这是我的登录复选框:

<label>
    <input type="checkbox" id="remember_me" name="_remember_me" value="remember-me" checked> Remember me</label>

我是不是漏掉了什么?

remember_me 配置选项不用于该目的。正如 doc 中所说:

Once a user is authenticated, their credentials are typically stored in the session. This means that when the session ends they will be logged out and have to provide their login details again next time they wish to access the application. You can allow users to choose to stay logged in for longer than the session lasts using a cookie with the remember_me firewall option

它只是说通过使用 cookie,会话将比普通会话变量持续更长时间。

默认情况下,会话不会在您关闭浏览器时销毁。

在这两篇文章中,您可以在 PHP 中找到有关如何执行类似操作的更多信息,这可能会帮助您解决问题。

Post1

Post2