Symfony 3.0.1 CSRF令牌存在但无效 [英] Symfony 3.0.1 CSRF token present but invalid
问题描述
我在重新安装Symfony 3.0.1时遇到了这个奇怪的问题.我用表单PostType生成了一个新的CRUD控制器,该表单包含一个URL和一个标题.没什么.
I am having this strange issue with a fresh Symfony 3.0.1 installation. I generated a new CRUD Controller with a Form PostType which contains an url and a title. Nothing fancy.
该窗体将按预期方式呈现.它同时包含我的url字段和title字段.在表单内部,还会显示隐藏的输入字段_token.
The form is rendered as expected. It contains both my url field and title field. Inside the form the hidden input field _token is also rendered.
提交此表单时,我一直都遇到以下错误:
When submitting this form, i am getting all the time the following error:
The CSRF token is invalid. Please try to resubmit the form.
因此令牌被添加到表单中,它包含一个值,我有一个恒定的PHP会话cookie值,只是此令牌无效.
So the token is added to the form, it contains a value, i have a constant PHP session cookie value, it is just that this token invalid.
我已经搜索了其他答案,但是类似的问题都是由于缺少_token输入引起的.
I have searched for other answers but the similar questions are all caused by the absence of a _token input.
在Symfony 3.0.2/3.0.3.中也会发生此问题.
This problem also occurs in Symfony 3.0.2/3.0.3.
推荐答案
在我的情况下,原因是var/sessions/
文件夹不可写.默认值为var/sessions,它在config.yml中设置.
In my case it was that the var/sessions/
folder wasn't writable. The default is var/sessions which is set at config.yml.
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
确保您具有var/ folders
可写.
chmod 775 -R var/sessions/
chmod 775 -R var/log/
chmod 775 -R var/cache/
这篇关于Symfony 3.0.1 CSRF令牌存在但无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!