I'm not sure if this has been discussed before so if it has just ignore.
If a user accesses the site, from http://drupal.org
When a cookie is set, it is set to domain:
drupal.org
Now if a user accesses the site from http://*.drupal.org, including http://www.drupal.org
The cookie will be set to
*.drupal.org
The problem is that if a user accesses the site from a different url, the cookie doesn't work.
So if I login via http://drupal.org, and then access http://www.drupal.org it will apprear as if i am logged out.
Hope this helps!
Comments
Comment #1
pcrov commentedI haven't dug into the code, but setting the cookie domain with a leading '.' (.drupal.org) would take care of that.
Comment #2
Damon-1 commentedThe leading full stop (.drupal.org) would still not match just http://durpal.org, as there is no full stop in the url before the domiain.
Comment #3
pcrov commentedIt does work. I do this with a postnuke installation and just tested it with drupal-cvs. If you want to try it you can edit user.module line 579 (this is the line number in a cvs snapshot from a couple days ago, not sure of the number for 4.1). Find:
replace it with:
changing 'yourdomain' for your domain name
Comment #4
adrian commentedI have done some research , specifically re: single logins across multiple domains.
IE: log into osdn (slashdot) , and you are logged into thinkgeek and newsforge aswell. (all running on totally different domains , not even subdomains).
It seems the trick is to use a web bug. ie : an tag pointing to a php script lying on the main domain (ie: osdn.com) , when you are on a new domain that doesnt have a login session .. it replicates the login cookie from the main site via headers.
I am still doing more research into this , as I realized single login -> multiple domains are something i could really use =)
Comment #5
tbecker commentedadrian's work aside, I think that the easiest way to address
www.mysite.orgversusmysite.org, at least for me, was to set$base_urlininclude/conf.phptowww.mysite.org.This way, anyone accessing my site at
mysite.orghas to follow a link towww.mysite.orgin order to log in, so the cookie is always set that way.Moving logins from
*.mysite.orgto*.anothersite.orgis another matter entirely. And a lot more work!Comment #6
moshe weitzman commentedthere is no bug or clear feature request in here. marking 'by design'
Comment #7
al commentedDisagree with marking BY DESIGN.
Have changed to a feature request and updated the summary.
Drupal should redirect users from http://www.foo.com to http://foo.com in order to resolve issues with the handling of cookies between these domains.
This should probably be an admin-configurable option, or maybe even provided by an additional module using the _init hook?
Comment #8
moshe weitzman commentedHave a look at redirect.module in Contrib. I forgot that I wrote that
oen. Wil work finr for this purpose. It uses the _init() hook as you
suggest.
Al Maw wrote:
Comment #9
al commentedHmmm... I'm not sure quite what to do with this one. I'm tempted to WONTFIX it, as the problem can be solved elsewhere. However, this is a common problem, as most people these days run sites at foo.com and www.foo.com and expect people to appear from either.
Lots of people have this issue, so I'm therefore thinking that a fix that solves this problem should be incorporated into the core Drupal release, and not be something you can do with a contrib module provided you read all the docs and hunt around for it.
What do other people think?
Comment #10
dries commentedCan't you define the
session.cookie_domainvariable in your.htaccessfile, or set it on the fly usingsession_set_cookie_params()?Comment #11
al commentedYes, you can, but its an inferior solution, as lots of IE6 users have their default security policy set up to block cross-domain cookie use.
Comment #12
moshe weitzman commentedThe fixes suggested by Paul_C and Dries do indeed work. Just set the cookie with a leading '.'. I tested with several browsers. See drupal.org, which sets its cookie to .drupal.org.
I think this is a documentation issue at this point.
Comment #13
sethcohn commentedAdrian wrote some time ago:
I have done some research , specifically re: single logins across multiple domains.
IE: log into osdn (slashdot) , and you are logged into thinkgeek and newsforge aswell. (all running on totally different domains , not even subdomains).
It seems the trick is to use a web bug. ie : an tag pointing to a php script lying on the main domain (ie: osdn.com) , when you are on a new domain that doesnt have a login session .. it replicates the login cookie from the main site via headers.
I am still doing more research into this , as I realized single login -> multiple domains are something i could really use =)
Adrian's not the only one. Right now, using Drupal 'anywhere' logins, you have no selectivity if you open up your site to that... Any domain would work, and going from domain www.abc.com to www.xyz.com is NOT transparent, but requires yet another login (even if you could login using username@www.abc.com).
Please note this is NOT the same thing as sitea.abc.com and siteb.abc.com (which we have now)
Domain cookie security requires a work around to allow.
(See http://support.softartisans.com/kbview.aspx?ID=666 for an example I found that uses ASP)
Adrian's description is pretty much the same idea.
Adding this functionality would allow someone with 2 or more related drupal-running domains to easily share users as they can (say all using a single user table prefix) AND not force that user to relogin when going from one to the others...
When you think of all of the drupal-using multiple site hosts where the userbase is shared, this is a much needed functionality, and should be as simple as a user.module cookie change, combined with a conf.php addition (Is this site the master cookie, or a slave cookie? If master, what sites will I slave to, and if slave what site is my master cookie...)
Comment #14
moshe weitzman commentedin your php settings, you control what domain you wish to set cookies on. in your example, you could set the cookie on .abc.com and it is readable by both domains.
you might be interested in sso.module: http://drupal.org/project/sso. this module enables single sign on across dissimilar domains.
Comment #15
sethcohn commented"In your php settings, you control what domain you wish to set cookies on. in your example, you could set the cookie on .abc.com and it is readable by both domains."
That won't work for anyone who has cross-domain cookies off due to security (a default setting).
Setting .abc.com from .xyz.com is consider a poor practice and dangerous, so it's blocked.
However this _will_ work:
"you might be interested in sso.module: http://drupal.org/project/sso. this module enables single sign on across dissimilar domains"
It's deleted from the current CVS, so most links are broken, but looking in the attic, it's there (yeah for CVS). This does EXACTLY what I want, the right way.
But it's unmaintained... someone feel like taking it on, or do I have go get a drupal account for myself and do it? I can't even move this thread to the sso project...
Comment #16
IamPter commentedHow do you get the cookie from being lost when you have a setup like mine.
You can get to my site by multiple methods:
http://www.apockotos.com <- Baseurl set in the settings
But the site can be accessed by:
http://apockotos.com
http://www.apokotos.com
http://apokotos.com
http://www.peterapockotos.com
http://peterapockotos.com
and if someone does use these alternatives the cookie is lost and user has to re-login.
Is there an easy resolution for this?
Comment #17
LAsan commentedFeature request moving to cvs.
Comment #18
sunFrom settings.php:
If you want a single, shared login across multiple domains (base domains), you might want to use http://drupal.org/project/singlesignon module. However, Drupal core won't support such advanced use-cases by default, because they require some more trickery and you should know what you are doing and why you are doing something.
Comment #19
timtrinidad commentedI know this is an old issue, but the title is exactly what I need (even if the message bodies might have gotten more specific.)
I have a Drupal site that allows users to have custom subdomains. Consider the following:
I haven't fully tried it yet, but would setting the following in settings.php work?
$cookie_domain = $_SERVER['HTTP_HOST'];