Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top