After user enter email and password. hook_user_login gets triggered and excute below code. I am placing code in "bootstap_business.theme" file like this

function hook_user_login($account) {

$email = $account->geteMail();

echo "Email: $email";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://example.com/users" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, "$email" );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain','Authorization: ff23fdcffdgh5dsdsds'));

$result=curl_exec ($ch);


But i am not getting whether this function is excuted or not. How can i debug/solve this problem. If i do echo also its not printing anything.

2 Answers 2


Only alter hooks and some specific theme-related hooks can be implemented in a theme.

hook_user_login isn't one of them, you need to implement it in a module.

To create a custom module see the official Creating custom modules docs. You essentially need a .info.yml file and a single .module file containing this:

function MYMODULE_user_login($account) {
  // Your code here
  • Thank you @clive . Actually i am new to drupal. Can u plz sugguest how to implement it in a module.
    – MH9
    Jun 15, 2017 at 7:19
  • Added an example @Mithun
    – Clive
    Jun 15, 2017 at 10:00

Try to implement hook in the module. Suppose you are creating new module name 'example', then this code for the module file.

 * Implement hook_user_login

function example_user_login(&$edit, $account) {
    $email = $account->mail;
    echo "Email: $email"; exit;
  • This will work in Drupal 7 but not Drupal 8
    – Clive
    Jun 15, 2017 at 10:00

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.