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?

1 Answer 1

2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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