Skip to content

Instantly share code, notes, and snippets.

@sadanandkenganal
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadanandkenganal/be48de672f6ecb176a9c to your computer and use it in GitHub Desktop.
Save sadanandkenganal/be48de672f6ecb176a9c to your computer and use it in GitHub Desktop.
Redirect users after login in drupal7.

How to redirect users after login in drupal?

For example, there is page called user-serach. I want to redirect to a user-search page, when the user of some ROLE 'user-search-role'.

For this, you need to implement, hook_user_login(&$edit, $account).

Complete Code

/**

  • Implements hook_user_login().` */ function hook_user_login(&$edit, $account) { // Do not redirect when the user is resetting her/his password. if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset') { if (in_array('user-search-role', $account->roles)) { drupal_goto('user-serach'); }
    } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment