3

In a custom module, I'd like to redirect anonymous users to the login page. After a successful login the user should get to the page he intended to see.

I tried the following code. This gives me the login form, but the user is never sent to the destination page. Instead the standard user page gets displayed.

if (!$user->uid) {
    $dest = drupal_get_destination();
    drupal_goto('user/login', $dest['destination']);
}

Any ideas how to fix that?

2

Have you tried drupal_goto('user/login', array("query" => array("destination" => $dest['destination'])))?

  • Thanks! Didn't realize realize that it's double indexed. – BetaRide Nov 29 '11 at 12:43
  • You can use drupal_get_destination() function. drupal_goto('user/login', array('query' => drupal_get_destination())); – milkovsky Sep 27 '13 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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