Beaker session across multiple sub-domains

154 views
Skip to first unread message

Pavel Skvazh

unread,
Aug 21, 2008, 9:13:10 AM8/21/08
to pylons-discuss
The case is that when I work with sub-domain (i.e. my.example.com),
set some session variables and then go to some other domain (i.e.
www.example.com) the session is empty. No cookie is issued as well.

Have anyone faced this issue before and what's the best practice to
keep the session persistent across sub_domains

Thanks!

Cezary Statkiewicz

unread,
Aug 21, 2008, 9:53:37 AM8/21/08
to pylons-...@googlegroups.com
2008/8/21 Pavel Skvazh <pavel....@gmail.com>:

Yes. In general:

* setup routing with subdomain=True:

http://routes.groovie.org/manual.html#sub-domain-support

* add to your config.ini

base_domain = yourbasedomain.com

* add BaseController.__before__ code:

if session.is_new:
session.cookie[session.key]['domain'] =
'.%s'%request.environ['paste.config']['app_conf']['base_domain']
session.cookie[session.key]['path']= '/'
session.request['cookie_out'] =
session.cookie[session.key].output(header='')

Note however, that this trick is pre 0.9.6. Now it might be easier to setup.

Best regards,

Cezary Statkiewicz

--
Cezary Statkiewicz - http://thelirium.net
rlu#280280 gg#5223219
jabber://ce...@jabber.org

Pavel Skvazh

unread,
Aug 21, 2008, 10:43:54 AM8/21/08
to pylons-discuss
Thanks a lot for the fast response!

Haven't got time to give it a deep look, but plug and play method
didn't work.
Beaker evolved a lot lately so plobably this hack won't work with the
latest version.

It'll be great if probably Ben could take a look and hint on the best
practice way to achieve this.

On Aug 21, 5:53 pm, "Cezary Statkiewicz" <c.statkiew...@gmail.com>
wrote:
> 2008/8/21 Pavel Skvazh <pavel.skv...@gmail.com>:
>
>
>
> > The case is that when I work with sub-domain (i.e. my.example.com),
> > set some session variables and then go to some other domain (i.e.
> >www.example.com) the session is empty. No cookie is issued as well.
>
> > Have anyone faced this issue before and what's the best practice to
> > keep the session persistent across sub_domains
>
> Yes. In general:
>
> * setup routing with subdomain=True:
>
> http://routes.groovie.org/manual.html#sub-domain-support
>
> * add to your config.ini
>
>    base_domain = yourbasedomain.com
>
> * add BaseController.__before__ code:
>
> if session.is_new:
>     session.cookie[session.key]['domain'] =
> '.%s'%request.environ['paste.config']['app_conf']['base_domain']
>     session.cookie[session.key]['path']= '/'
>     session.request['cookie_out'] =
> session.cookie[session.key].output(header='')
>
>  Note however, that this trick is pre 0.9.6. Now it might be easier to setup.
>
>  Best regards,
>
>  Cezary Statkiewicz
>
> --
> Cezary Statkiewicz -http://thelirium.net
>  rlu#280280 gg#5223219
>  jabber://ce...@jabber.org

Ben Bangert

unread,
Aug 21, 2008, 12:09:25 PM8/21/08
to pylons-...@googlegroups.com

You need to specify to use just the last portion (.example.com) for
the beaker cookie. You can set this in your ini file with:
beaker.session.cookie_domain = .example.com

Cheers,
Ben

Pavel Skvazh

unread,
Aug 25, 2008, 9:17:04 AM8/25/08
to pylons-discuss
Solved. Thanks as usual, Ben!
>  smime.p7s
> 3KViewDownload
Reply all
Reply to author
Forward
0 new messages