Symfony 3:如何在子域上共享Cookie? [英] Symfony 3: How to share the cookie on subdomain?

查看:93
本文介绍了Symfony 3:如何在子域上共享Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站中有两个以上的子域。
,例如:www.example.com,login.example.com,user.example.com,cart.example.com ...
i设置cookie_domain在config.yml中为.example.com, php.ini
,当我setCookies('test','value','.example.com'),但cookie始终不在子域中共享。
那么,现在该怎么办?

i have over two subdomains in my site. such as:www.example.com, login.example.com, user.example.com, cart.example.com... i setup the cookie_domain is .example.com in config.yml and php.ini when i setCookies('test', 'value', '.example.com'), but the cookie is always not shared in the subdomain. so, how to do now?

有我的config.yml

there is my config.yml

session:
    handler_id:  session.handler.native_file
    save_path:   "%kernel.root_dir%/../var/sessions/"
    cookie_domain: .example.com
    cookie_lifetime: 0
    name: TESTSESSIONID

在我的安全下:

security:
    session_fixation_strategy:  none


推荐答案

我需要此功能可用于所有子域,但是域本身会根据我是开发中的还是生产中的而更改。

i needed this to work for all subdomains, but the domain itself changed depending on whether i was developing or in production.

我使用parameters_dev.yml和parameters.yml定义域,然后将其添加到config.yml中,以允许cookie遍历所有子域。

I use parameters_dev.yml and parameters.yml to define the 'domain', then added this in config.yml to allow cookies accross all subdomains.

framework:
session:
    cookie_domain: '.%domain%'

这篇关于Symfony 3:如何在子域上共享Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆