我已经以这种方式配置了我的网络服务器:
<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 }
为什么会这样?
答案 0 :(得分:2)
您必须在config.yml中设置cookie域:
framework:
session:
cookie_domain: .example.loc