Fixed “elusive login issue” in Drupal!

By John, 15 March, 2007

Back at the beginning of February, chx (a Drupal master coder) posted a story to Drupal’s homepage asking for people to come together and work on an “elusive login issue” that people had been reporting for over a year. Some users were reporting that no matter how many times they tried to login to Drupal, they would be promptly put back in front of the login form without the anticipated “Unrecognized username or password” error message.

A Simple, Desultory Bug Hunt
(Or How I Was chx'd Into Submission)

At the time I was not able to reproduce the problem, and so couldn’t partake in the bug hunt. But that changed last night…

...for the life of me, I could not log in! I was going to do some work on a client’s website, so I pulled up my development version of it at (the name’s have been changed to protect the innocent) and, for the life of me, I could not log in! I tried again. And again. I drank some tea. I tried again. I knew that I had the username and password correct, but still no go.

So I tried a different browser (as any first-level support lackey would tell you), and I was magickly able to login with the same username and password. No problems. I drank some more tea. I then headed over to Drupal’s logs and it shows multiple, successful logins just a few minutes before. O… K…

I then dived into the MySQL database and looked at the sessions table to see the most recent session IDs. The last session ID is the one reported in my 2nd browser’s cookie for The third-to-last session ID is the one reported in my 1st browser’s cookie for But where’s the second-to-last session ID coming from?

Nobody is trying to login besides me; I’m on a private nework! Should I look for script kiddies next to the dust bunnies in my office? And then I spot it! That mysterious session ID is the same as the one on my 1st browser's cookie for!

It all came together for me then… the browser was sending both cookies (because they both match the tail end of the server name), but Drupal was only able to see the cookie; the wrong cookie!

A Critical Bug

Because this bug prevents users from successfully logging in, this is actually a critical bug. :-D …should I be giddy for finding a critical bug? :-( erm… Anyway, moving on… I’ve posted a patch to Drupal core over at and hopefully it will get rolled into the not-yet-released Drupal 5.2 and Drupal 4.7.7.

…and the reason I had never experienced that login bug until last night? I had finally gotten around to installing Drupal on a few weeks ago. There were simply no cookies in my browser before. Oh, the humanity!

Topics: Drupal, Cookies


The content of this field is kept private and will not be shown publicly.

fiLi (not verified)

16 years 11 months ago

Oh, at last!

Thank god I found this post...
Thank you for fixing this...


I had the same problem with Drupal 5.x. As far as I can tell the RFC that specifies how sessions are maintained (RFC 2109) does not allow port specifications. The PHP code used in Drupal 5 does NOT strip ports from the cookie_domain.

Now it has been solved,thanks for the post!!!

MorayJ (not verified)

15 years 7 months ago


I'm running drupal 6.4 and I'm still getting this problem. It's driving me nuts. Pretty fundamental problem.