0

I am trying to create a method to log the actions of users, specifically when they log in and out. I am using hook_user() method to do this. This is my code.

function mymodule_user($op, &$edit, &$account, $category = NULL) {
     switch ($op) {
        case 'login':
            //log to db
           break;
         case 'logout':
           //log to db
            break;
    }
}

There are two problems with this code, and I can't figure out how to fix them.

When a user password is expired, and they attempt to log in, they are redirected to their profile page to change their password. In this event, $op is never "login" and, as such can never be loaded. Instead, $op = "load" but it is useless to log this as this hook gets called nearly 50 times (storing that much data would be to much). Is there a better way to capture this event?

Second, when a user logs out ($op = 'logout') all the other information about the user is lost: The $account array only has empty values (and I need the user ID). Is there a way to capture the logout event and know the user ID?

1 Answer 1

0

hope you are trying for drupal 7, there are hook for login and logout, hook_user_login and hook_user_logout respectively. the user id available for logout hook so you can populate the data you want about user.

1
  • No, I'm using Drupal 6.
    – jason
    Commented Jan 12, 2015 at 21:33

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.