Last updated May 11, 2012. Created on November 21, 2011.
Edited by agentrickard, MrPhilbert. Log in to edit this page.

If you are only using sub domains and don't intend to add any top level domains, then just setting the cookie domain in your settings.php file works fine (example: $cookie_domain = '';).

However, if you intend to add another top level domain as an affiliate you won't be able to log on to the new top level domain by using the above. The above will only add a cookie to the domain you just named and since Drupal uses cookies to store session data, you won't be able to log on to the other top level domain. The solution is to set the cookie with a conditional statement. E.G.:

if (isset($_SERVER['HTTP_HOST']) && substr_count($_SERVER['HTTP_HOST'], '') > 0) {
$cookie_domain = '';

Now you can also login to the other top level domain as it has not satisfied the condition of the conditional statement above. If you also want to add wildcard sub domains to other top level domains, just continue the above condition with an "else" for each top level domain you want to use.

Note: This will only work if your domains are pointed to the default sites folder.

Thanks to Agent Rickard for the code above.

Looking for support? Visit the forums, or join #drupal-support in IRC.


drvdt’s picture

Whai is Is it my domain?
In case, I have many domains, What should I do?

My sites: Medicare

damianleuthold’s picture

This page was the solution to my problems thanks! It took me a long time to find this as I was using other search terms. I thought I'd add them in this comment so someone in a similar situation can find this easier.

I had installed Domain Access and was adding secondary domains. Things looked good until I tried to log in via a secondary domain. I was able to log in but unable to access the admin menu overlay. I then noticed many, but not all, of the java scripts that loaded on the default domain were not loading on the secondary domains. I then searched for terms like 'domain access missing admin menu' and 'domain access missing java script' and not finding the solution until I looked again at the install documentation and found this page.

Hope this helps someone else.


DrupalChimp’s picture

Brilliant, worked for me. Thanks for the tip

Oddy94’s picture

I have multiple domain names accessing the same drupal site, so I had problems with creating a HybridAuth Session.

Luckily I've found this article. Thank you very much for sharing!

mzeyrek’s picture

Anyone knows where can i configure cookie_domain like this ? I've checked settings.php but nothing there wonder if it works adding this code