Redirect user after login

Public
</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_user_login().
  3.  */
  4. function module_name_user_login(&$edit, $account) {
  5. // Don't redirect on password reset.
  6. $current_menu_item = menu_get_item();
  7. if ($current_menu_item['path'] == 'user/reset/%/%/%') {
  8. return;
  9. }
  10. // Redirect user to profile page after the login.
  11. $_GET['destination'] = 'user';
  12. }

Comments

timonweb's picture

Hey, nice evolution of the idea!

alex.barylski's picture

Cool, I implemented something very similar myself a while back and discovered it foobar'ed with the password reset functionality, so I had to check for the condition and continue as normal:

  1. <?php
  2. if (arg(0) == 'user' && arg(1) == 'reset'){
  3. // Just let it fly
  4. }
  5. else{
  6. if($user->uid == 1){
  7. drupal_goto('admin');
  8. }
  9. else{
  10. drupal_goto('products/listings');
  11. }
  12.  
  13. exit;
  14. }