0

我以这种方式配置了我的网络服务器:

<VirtualHost *:80>
ServerName example.loc
ServerAlias www.example.loc

DocumentRoot /var/www/example/web
<Directory /var/www/example/web>
    AllowOverride All
    Order allow,deny
    Allow from All
</Directory>

ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined

问题是,如果我转到 example.loc 并登录,然后我访问 www.example.log,则不会共享会话。

就好像访问一个完全不同的网站!

这是我的配置 security.yml:

security:
encoders:
    FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

providers:
    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
    main:
        switch_user: true
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            login_path: fos_user_security_login
            check_path: fos_user_security_check
            default_target_path: reserved_area_index
        logout:
          path: fos_user_security_logout
          target: homepage
        anonymous:    true

access_control:
    - { path: ^/[^/]+/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/[^/]+/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/[^/]+/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/[^/]+/reserved_area, role: IS_AUTHENTICATED_FULLY }

为什么会这样?

4

1 回答 1

2

您必须在 config.yml 中设置 cookie 域:

framework:
    session:
        cookie_domain: .example.loc
于 2013-09-05T21:49:27.263 回答