I'm storing the session details from Drupal to share with another system, so users don't have to log in twice for each system.

It appears that my hook_user_login is being called twice. Right now I'm just calling:

mymodule_user_login(&$edit, $account) {

to see if the session I'm storing is the same as the session being used.

I'm getting the debug statement twice, with two different session_id values. Am I missing something here?

  • Are you sure there is just a logged-in user when you are executing that code?
    – apaderno
    Dec 29, 2011 at 19:32
  • Yes, it's my own dev machine, and I'm the only one connected, and the only one with the test credentials. I am authenticating against my own user db however, but I can't see how that would trigger two login hooks
    – TomCDona
    Dec 29, 2011 at 19:39
  • If you are already logged in when executing that code, and there isn't code that impersonates another user, that hook should not be more than once. It is rather difficult to say what it is going on, though.
    – apaderno
    Dec 29, 2011 at 19:48
  • I'm starting from anonymous, and then logging in. Is the anonymous session playing somehow in this?
    – TomCDona
    Dec 29, 2011 at 19:55
  • the session_name() isn't changing, just the session_id(). Does calling session_id() change its value?
    – TomCDona
    Dec 29, 2011 at 20:19

1 Answer 1


I know this is not an answer (I don't yet have enough reputation to post a comment); I am also uncertain if you are still looking for answer. It is possible sometimes for distributed modules to call user_login_submit.

For example, the D7 LDAP module's _ldap_authentication_user_login_authenticate_validate calls user_login_submit, which causes the user login form to fork two calls to user_login_finalize, both of which triggers hook_user_login. If you are still experiencing this problem, one possible way to debug your application is to use PHP XDebug, and dsm function traces.

After you have installed XDebug, you can use xdebug_call_function() on user_login_submit, user_login_finalize, user_module_invoke to see where the two calls of hook_user_login are coming from. I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.