Advertising sustains the DA. Ads are hidden for members. Join today

Login Destination - 6.x

Login Destination project page.

What is the Login destination module?

The login destination module provides a way to customize the destination that the user is redirected to after login

What features does the Login Destination module offer?

The Login destination module provides very nice features including:

  • A customizable login destination page in the form of a static URL
  • Ability to customize the login destination using php code
  • Only apply the login destination rules when logging in from certain pages
  • Setup php rules of evaluating when to apply the login destination rules

You can get an inside look at the module and view a demo of its features on the Login Destination Module Preview

Drupal 6.x

You can provide a PHP snippet that returns a string or returns an array: (ONLY when there is a GET query at the end of the url - like /example?var1=value)
Example: (note the absence of the "?" sign)

        return array('path' => 'node/add/video', 'query' => 'param1=100&param2=200');

How to return users to their original page

If (and only if)

  • you are trying to redirect your users back to where they were after logging in
  • and you take them to "/user" to login (the default login page)

... then you will need to make the "login" link leading to that page to look like:

"/user?destination=<strong>current-page</strong>"

You can do this by creating a custom block and using php there:


global $base_url;
global $user;


$destination = __custom_postproccess_destination_url(drupal_get_destination());

function __custom_postproccess_destination_url ($destination_plus_path_with_query) {
  // urldecode, then remove "destination=", then split with ?-s
  $parts = explode ("?", preg_replace("!^destination=!",  "", urldecode($destination_plus_path_with_query) ) );

  // should be equal to $_GET['q'] from above
  $path_wo_query = $parts[0];

  $query = $parts[1];

  if ($query != "") {$query = "?". $query;}

  $alias = drupal_get_path_alias($path_wo_query);

  return "destination=" . urlencode($alias . $query);
}


// use the $destination var below.

// logged in
if ($user->uid) {

  print '<a href="' . $base_url . '/user/'.$user->uid.'">Profile</a><br />
<a href="'.$base_url . $base_path.'/logout">Logout</a>';

} // not-logged in (= anon)
else {

  print '<a href="' . $base_url . $base_path.'/user/login?' . $destination . '">Login</a><br />
<a href="'.$base_url . $base_path.'/user/register">Register</a>';

}

Drupal 5.x

$_SESSION['login_page'] was added and stores the page you were before clicking login form button. You can use it to determine the page you logged from instead of $_GET['q'] because $_GET['q'] always equals to 'login_redirect'.

Login Destination Snippets

PHP Snippets Library:

Guide maintainers

sapark's picture