Index: sites/default/settings.php
===================================================================
RCS file: /cvs/drupal/drupal/sites/default/settings.php,v
retrieving revision 1.41
diff -u -p -r1.41 settings.php
--- sites/default/settings.php	7 Feb 2007 10:58:31 -0000	1.41
+++ sites/default/settings.php	11 Feb 2007 00:24:34 -0000
@@ -141,11 +141,12 @@ ini_set('url_rewriter.tags',        '');
  * try commenting out the code below or specifying the cookie domain by hand.
  */
 if (isset($_SERVER['HTTP_HOST'])) {
-  $domain = '.'. preg_replace('`^www.`', '', $_SERVER['HTTP_HOST']);
+  $domain = $_SERVER['HTTP_HOST'];
+  $domain = preg_replace('|^.*([^.]+\.[^.]+)$|', '\1', $domain);
   // Per RFC 2109, cookie domains must contain at least one dot other than the
   // first. For hosts such as 'localhost', we don't set a cookie domain.
-  if (count(explode('.', $domain)) > 2) {
-    ini_set('session.cookie_domain', $domain);
+  if ($domain != $_SERVER['HTTP_HOST']) {
+    ini_set('session.cookie_domain', '.'. $domain);
   }
 }
 
