php - Symfony2 "This authentication method requires a session"登录检查错误

标签 php security symfony session

我一直在尝试按照 Symfony 书中的说明实现一个简单的表单登录,但我在登录时卡住了。 每当我尝试登录时,我都会收到从 AbstractAuthenticationListener::handle 抛出的“此身份验证方法需要 session ”错误。 我搜索了 Symfony 的书和​​食谱以及谷歌,但没有找到答案,甚至没有找到一些相关问题。

这是我误解了书中的内容还是我的服务器配置错误?

如果您需要代码提取,请不要介意询问...

安全.yml

security:
  encoders:
    Common\Bundle\UserBundle\Entity\User:
      algorithm: bcrypt
      cost:      10
  providers:
    main:
      entity: { class: CommonUserBundle:User }
  firewalls:
    main:
      pattern:   ^/
      provider:  main
      anonymous: ~
      simple_form:
        authenticator: simple_authenticator
        login_path:   /Connexion
        check_path:   /Connexion/verifier
      logout:
        path:   /Deconnexion
        target: /
      remember_me:
        key:      "%secret%"
        lifetime: 2592000
        path:     /
        domain:   ~

配置.yml

  framework:
    secret:    "%secret%"
    fragments: { path: /_fragment }
    router:
      resource: "%kernel.root_dir%/config/routing.yml"
    validation:
      enable_annotations: true
    templating:
      engines: ['twig']
    default_locale: "%locale%"
    http_method_override: true

最佳答案

您需要启用 PHP session 来保持用户登录。您的 config.yml 文件看起来未启用,在 framework 根级别添加一个 session 部分:

这是默认配置:

framework:
    # ...
    session: ~

查看官方文档以了解如何配置 session 存储:http://symfony.com/doc/current/reference/configuration/framework.html#session

关于php - Symfony2 "This authentication method requires a session"登录检查错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25248490/

相关文章:

php - 检查用户是否在 symfony 中被重定向?

PHP 静态属性和 const 覆盖

php - 带有类型文件的 Symfony 2 表单集合字段

php - 服务器端脚本的数据表身份验证

security - Vaadin 21 流程 + Spring Security OAuth2 : Couldn't find route for 'oauth2/authorization/google'

python - 如何安全存储敏感数据?

javascript - 例如,在使用 JWT 时如何保持共享 secret ?

php - 原则 2 并发问题

php - 隐藏输入仅从循环数据中获取最后一个值-php

php - 如何在 Facebook 的 PHP SDK 中获取全尺寸个人资料图片?