Last updated May 11, 2012. Created by MrPhilbert on November 21, 2011.
Edited by agentrickard. 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 = '.topdomain.com';).

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.:

<?php
if (isset($_SERVER['HTTP_HOST']) && substr_count($_SERVER['HTTP_HOST'], 'parentdomain.com') > 0) {
$cookie_domain = '.parentdomain.com';
}
?>

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 Drupal.org forums, or join #drupal-support in IRC.

Comments

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