I needed to set up a test site to day, so I set up a subdomain, copied the database cleared the cache and session tables, copies of the files from the working site, edited settings.php to use the new database and it worked, almost.

I could not login, not matter what I tried the login would not stick. There are many posting related to this (http://drupal.org/node/6696 is one) and I tried many fixes and non seemed to work. But I wondered why one of the simple fixes did not work, it had been suggest to add

ini_set('session.name', ;yourname');

to settings.php (in the PHP settings section. This one seemed promising but while it worked for some it did not work for me. So I spent some time trying to figure out what was going on and the session cookie was not being set. So I modified sess_regenerate() in session.inc so the last three lines read

  session_regenerate_id();
  setcookie(session_name(), session_id(), 0, '/'); // I added this to make sure the cookie is set
  db_query("UPDATE {sessions} SET sid = '%s' WHERE sid = '%s'", session_id(), $old_session_id);

and things now work,

I consider this a bandaid since I do not understand where the cookie should be set. If I do not add ini_set('session.name', ;yourname'); to settings.php the default name of 'PHPSESSID' is used, the cookie is set, but the login does not stick. On the other hand if I set session.name and make sure the cookie set the login does stick.

So the question is does anyone have any insight in to what is happening here?

Thanks