Can someone please clear this up for me. I cannot use drupal_goto in hook_user() on case login. The following is not working:

function my_module_user($op, &$edit, &$user, $category=NULL){
  if($op=='login'){
    drupal_goto('my/module/url');
  }
}

Just to be clear, my module's name is my_module and this code is definitely getting called. How can I redirect the user to a page on login if they meet some criteria? For my module they will have a returned payment that did not go through and we need to redirect them to a certain page.

Comments

cyberswat’s picture

<?php
function my_module_user($op, &$edit, &$user, $category=NULL){
  if($op=='login'){
    $url = url('my/module/url');
    header("Location:$url");
    exit();
  }
}
?>
j_ten_man’s picture

Good idea. I went about it in a slightly different way by setting a Session variable and then calling drupal_goto if that variable is set.

nqsang’s picture

Thanks a lot!
Most other methods do not work for me. But this.

greenmachine’s picture

Please see this comment on making drupal_goto work within hook_user: http://drupal.org/node/580144#comment-3368072

jordotech’s picture

This was my problem, I had /user?destination=node which overrides drupal_goto() apparently.