在我的 symfony2 应用程序中,我尝试使用默认启用的“记住我”功能来登录用户。 cookie 设置正确,但用户在一段时间后仍会注销(我想说大约一个小时)。这种情况发生在我的开发机器、临时版本和生产版本上。
security.yml:
firewalls:
default:
pattern: ^/
anonymous: ~
form_login:
login_path: frontend_user_login
check_path: frontend_user_loginCheck
username_parameter: user[email]
password_parameter: user[password]
remember_me: true
logout:
path: frontend_user_logout
remember_me:
key: "%secret%"
lifetime: 31536000 # 365 days in seconds
path: /
domain: ~ # Defaults to the current domain from $_SERVER
config.yml:
framework:
session:
cookie_lifetime: 31536000
cookie_httponly: true
handler_id: ~
name: mycookie
在 Chrome 中查看我的 cookie,它显示:
Name: mycookie
Content: hqafha2ut4rpl4bdnh2jhcfm34
Domain: REPLACED
Path: /
Send for: Any kind of connection
Accessible to script: No (HttpOnly)
Created: Thursday, January 8, 2015 at 10:46:36 PM
Expires: Friday, January 8, 2016 at 10:46:36 PM
我使用 php.ini 中的 session.save_handler = redis
设置将 session 存储在 redis 中。这个问题在我切换到redis之前确实存在,并且过程中没有改变,所以我认为不是问题所在?
我还有什么遗漏的吗?可能有一些我需要注意的 php.ini 配置吗?
最佳答案
我认为这一行会对您有所帮助(只需将其添加到您的登录表单中):
// ../path/to/login.html.twig
<input type="hidden" name="_remember_me" value="1" />
关于php - 记住我没工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27850272/