Hi there,

On this page (http://drupal.org/node/49605) there is some explanation on setting up a single codebase, shared database, shared sign-on installation. Could you please add the following at the bottom of that page, before the "Some things which can be improved:" part?

Thank you,

Sander Toonen

P.s. My English sucks, so please edit when i'm talking garbage

Sharing sessions among subdomains:

In the settings.php file of each individual site you will find the following code:

  $domain = '.'. preg_replace('`^www.`', '', $_SERVER['HTTP_HOST']);

This codes ensures that sessions will only be valid at the subdomains when you logged in at example.com, www.example.com or that specific subdomain. When you log in at sub.example.com, your will still be logged out when visiting sub2.example.com. If you want your sessions to be valid throughout the entire domain regardless where you logged in, uncomment that line and add the following code underneath:

  $domain_parts = array_reverse(explode(".", $_SERVER['HTTP_HOST']));
  $domain = '.' . $domain_parts[1] . '.' . $domain_parts[0];

This code will set your cookie domain to .example.com, even if you log in at sub.example.com.

Comments

pnm’s picture

Here's some alternate code:
$domain = '.' . implode('.', array_slice(explode('.', $_SERVER['HTTP_HOST']), -2, 2));

which generalizes to 3rd and 4th level domain names like example.co.uk:

 $domain = '.' . implode('.', array_slice(explode('.', $_SERVER['HTTP_HOST']), -3, 3));
 $domain = '.' . implode('.', array_slice(explode('.', $_SERVER['HTTP_HOST']), -4, 4));
betz’s picture

Project: Documentation » Drupal core
Version: » 7.x-dev
Component: Installation » documentation

Changed the component to reflect the new component categorization. See http://drupal.org/node/301443

betz’s picture

Project: Drupal core » Documentation
Version: 7.x-dev »
Component: documentation » Correction/Clarification
heather’s picture

Component: Correction/Clarification » Outdated

The link to the handbook page is "Page not Found"

link rot: http://drupal.org/node/49605

I cannot locate a similar page.

I am marking this outdated. Can someone confirm this?

johnnoc’s picture

Status: Active » Closed (won't fix)

The poster wanted to add his code before the "Some things which can be improved" part. Since the given link results to "Page Not Found", I tried to search google for the exact phrase (http://www.google.com/search?q=%22Some+things+which+can+be+improved%22+s...). The Google result is only to this issue. Well...we cannot find the page so I'm marking this "won't fix". Besides, this is a 2 year old issue that is probably for Drupal 4.7 or earlier.