How can I redirect users on login with PHP? I'm trying to redirect users with certain roles to different pages on login.  Sample code is below:

function MYMODULE_user_login(&amp;$edit, $account) {
  // Allow users to reset their passwords
  if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset') {
    // Admin
    if (in_array('administrator', $account-&gt;roles)) {
      $redirect = 'admin/hud';
    }
    $edit['redirect'] = $redirect;
    dpm($edit);
    dpm($redirect);
  }
}


This is based on drupal.org login hook documentation about "How to redirect users after login in drupal?" and the answer to "Custom redirect on custom page for admin user".

The problem is that when I actually log in with a user having the given role, I am redirected to /user, not my custom path.  The results for dpm() for $redirect and $edit-&gt;redirect show the path specified in my code, so why am I not getting redirected there?  

I had this working in Rules, where there is a Force redirect checkbox.  But I am trying to move the code out of rules because it relies on a lot of custom PHP to check various conditions.
$edit['redirect'] = $redirect; doesn't stop other operations being executed I think.. The only thing I can think is to stop them with drupal_goto, but you should check you won't break anything else or not:

function MYMODULE_user_login(&amp;$edit, $account) {
  // Allow users to reset their passwords
  if (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset') {
    // Under 18
    if (in_array('administrator', $account-&gt;roles)) {
      $redirect = 'admin/hud';
    }

    drupal_goto($redirect);
  }
}