Index: sites/default/settings.php
===================================================================
--- sites/default/settings.php	(revision 6661)
+++ sites/default/settings.php	(working copy)
@@ -141,7 +141,8 @@ 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']);
+  // strip www., IP addresses, and port numbers from HTTP_HOST
+  $domain = '.'. preg_replace('`(^www\.|[\d:\.]+$)`', '', $_SERVER['HTTP_HOST']);
   // 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) {
