Login Destination Snippets
PHP Snippets Library:
Login Destination project page.
The login destination module provides a way to customize the destination that the user is redirected to after login
The Login destination module provides very nice features including:
You can get an inside look at the module and view a demo of its features on the Login Destination Module Preview
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¶m2=200');If (and only if)
... 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>';
}
$_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'.
PHP Snippets Library: