Drupal logins not working

There’s a long (and old) thread about Drupal logins not working. A lot of the problems are to do with weird PHP version changes; some of them are caused by cookie persistence; but the one we’ve had was the result of losing the login box on the front page.

“How can you log in without a login box?” I hear you holler. Well, even if you drop the block containing the login box from your frontend theme, you can have a separate theme for administering the site (useful as a visual distinction between admin and content editing). This theme can retain a login box. But if you try to log in at /admin, in the login box your admin theme still seems to have, then the submission workflow actually (I think) goes via your live site’s theme, where the form does not get instantiated. This means that Form API can’t handle your login and you just get taken to the front page.

The way we solved it is detailed in the comments to this post, but it basically involves stubbing out PHPTemplate’s core block.tpl.php and wrapping it as follows:

<?php if (! ($block->module == “user” && $block->delta == “0″)): ?>
  <!– .. original block content .. –>
<?php endif; ?>

This code effectively masks the output from the user-module-generated block #0, which is the login box. It doesn’t prevent the block from being generated (which is a minor performance issue, I suppose) and so the Form API hooks are all still activated and can grab onto your username and password.