On my main Drupal site, users need to be able to select a display preference (e.g. 'high visibility'). This will be available to registered and anonymous users but only for their session, so I plan to store their preference in a session variable:

$_SESSION['display'] = $my_preference;

Another Drupal site runs on a subdomain of the main site, and needs the same functionality. And if the user visits both sites, it would be great to remember their preference.

I think that if I uncomment this line in both site's settings.php, session variables can be accessed across sites on the same domain?

$cookie_domain = 'maindomain.com';

So then I could set $_SESSION['display'] on one site, and retrieve $_SESSION['display'] on the other?

Also, one site is D6 and the other D7 - will this be a problem? Is caching for anonymous users going to cause problems?

Am I on the right lines, or is this plan flawed? Thanks


There are two options to do this

  • Using session

Use a single session table for both the site using settings.php set up

  • Using Cookie

Use same cookie domain for both site and set cookie available in all pages.

| improve this answer | |
  • ah of course - sessions (and probably users) table needs to be shared between the sites. Thanks for the reply. – pushka Mar 22 '13 at 9:36
  • Be careful sharing tables across different sites. That particular solution can have erratic side effects. – Sam152 Jun 23 '13 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.