Ask Your Question
1

cookie domain-subdomain

asked 2011-07-14 03:36:39 -0600

DominiCattus gravatar image

updated 2011-07-20 07:29:33 -0600

Hi all!
I've deployed askbot on subdomain and I have another django application (blogs) that runs on main domain. Both share the same database, so users are registered and logged in only with askbot.
But now I want users that logged in on subdomain will be "logged in" on main domain automatically, and vice versa of course.
I added SESSION_COOKIE_DOMAIN = 'maindomain.com' to both askbot and blogs, but it doesn't help. What is common solution for this?
P.S. Tow applications are different django instances that everyone in its own virtualenv with own 'settings.py' file. Thanks!

edit:
Configs are same for two sites:

CACHES = {
'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
        'KEY_PREFIX': 'production'
           }
    }
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

#SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
SESSION_COOKIE_DOMAIN = '.domain.org'
SESSION_COOKIE_NAME = "sesid"

I've tried various session engines, but seems that problem is not here..

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-07-14 03:38:16 -0600

Evgeny gravatar image

updated 2011-07-14 03:42:17 -0600

Please try SESSION_COOKIE_DOMAIN = '.maindomain.com'

(With the leading "dot" before "mydomain")

Does that help?

edit flag offensive delete link more

Comments

No, doesn't help unfortunately. I see that both sites have cookie ".maindoman.com", share the same session_id, just askbot site have also askbot_csrf cookie, and csrf_token that points to "maindomain.com" without dot. When I log in to one site, the other doesn't detect it.. When I log in with this user on other site also, he is logged out on the first one. Strange...
DominiCattus gravatar imageDominiCattus ( 2011-07-15 01:40:42 -0600 )edit
The leading dot makes the cookies recognizable across subdomains, so for any cookies you want to work like that - add the dot. Does common login work? If not probably it is because you are not sharing the session data between the sites.
Evgeny gravatar imageEvgeny ( 2011-07-15 08:39:47 -0600 )edit
You're right. Looks like sessions conflict each with other. Any clue what can cause it? django_session is uniq table in DB that two sites use. Maybe caching sessions settings break the things here..
DominiCattus gravatar imageDominiCattus ( 2011-07-20 07:31:27 -0600 )edit
I think the two sites are using different sessions, even though you save them all in the same table, I am reading the docs now. But why don't you install both on the same django project - is that impossible?
Evgeny gravatar imageEvgeny ( 2011-07-20 13:04:08 -0600 )edit
Yeah.. Seems that it will be the final solution for this )) If using askbot as app, that's OK.
DominiCattus gravatar imageDominiCattus ( 2011-07-20 19:45:37 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-07-14 03:36:39 -0600

Seen: 1,510 times

Last updated: Jul 20 '11