Somewhat new to Drupal... this is probably a softball for all you Drupal pros out there.

I need to update a custom table in the database each time a user logs into Drupal. I thought I'd be able to do this within user.api.php and specifically within hook_user_login but it's as if none of the code I've put in there works. To debug I added the following 2 lines to try to email myself details about $account and I never get that either.

$o = print_r($account, true);
mail("[email protected]", "Login Output", $o, "FROM: [email protected]");

I've also gone into the Drupal admin area and saved the settings page for the modules thinking it was a Drupal caching issue related to its hooks. That didn't do it either.

Can someone tell me what I'm missing? I'd prefer to just take care of the database stuff here instead of creating an entirely new module and implementing the hook there.

Thanks in advance.


  • The *.api.php files are just documentation, for your question seems you're adding your code in there. Have you created a module for your code?
    – pcambra
    Jul 16, 2014 at 16:09

1 Answer 1


The .api.php files are documentation only, they're never included in a request.

hook_user_login() can only be implemented in a module, so you'll need to write one for this.

It's pretty straightforward, the Module developer's guide will get you started quickly.

  • Thanks Clive. Once I implemented this in my module all worked great. A friend who got back to me also told me to never change the core.
    – Art Geigel
    Jul 16, 2014 at 19:21

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.