-2

I am using below code to get the user login gender information & store in SESSION, I want to call below code after login, I already try this hook function bartik_user_login(&$edit, $account) {}but its not working. Please help. Thanks

if (user_is_logged_in())
{    
global $user;
    $uid = user_load($user->uid);
    $profile_main = profile2_load_by_user($uid, 'main');
    $field_iam = field_get_items('profile2',$profile_main,'field_i_am_field');
    $_SESSION['i_am']=$field_iam[0][value];
    echo $_SESSION['i_am'];
}

2 Answers 2

2

You should use preprocess function. For example -

function yourtheme_preprocess_user_login(&$vars) {
  $vars['intro_text'] = t('This is my awesome login form');
}

The general flow is:

theme($hook, $var) >> preprocess functions >> process functions >> finally either goto template.php or call theme function >> return output as string

therefore, template.php or theme function call is the final destination, no hook runs after template.php

2
  • take care that yourtheme should be replaced with your theme name. Your code will set the seesion variable. Use that session variable where ever you want. It will be set. Also any change in template.php file needs clearing the cache.
    – Parvind
    Sep 29, 2014 at 7:31
  • Thanks @Parvind.. Actually due to some silly mistake I was facing problem
    – Nishant
    Sep 29, 2014 at 9:29
2

You should use this hook in a custom module. You should also not tamper with core code as the Bartik theme directly. Also take a look at this:

How do I save session data for the anonymous users?

2
  • If I don't want to use custom module then is there any easy way through which am I put this code @Wtoser
    – Nishant
    Sep 29, 2014 at 7:16
  • 1
    @samzha This hook needs to be implemented in a module, you can't implement it anywhere else (unless you change how core works)
    – Clive
    Sep 29, 2014 at 8:11

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