Right now I'm using Login Destination with these settings:

Redirection Conditions - Always

Destination URL settings- PHP Snippet
global $user;
if (in_array('abc',$user->roles)) $path = 'abc';
elseif (in_array('def',$user->roles)) $path = 'def';
elseif (in_array('etc',$user->roles)) $path = 'etc';
else $path = '';
return $path;

Which works perfectly. The only problem is I want the admin role only to be redirected to the last visited page.

Of course when I click Preserve Destination, it overrides my PHP snippets (which is understandable) but how can I keep this functionality for select roles. Any suggestions?

Comments

3CWebDev’s picture

You could add code to your PHP snippet to check if the user belongs to the specified role and, if so, pull the destination out of the URL and perform the redirect through your snippet.

macandrow’s picture

Would I add this code to the current php snippet I have or place elsewhere?

I used to have the snippet below to redirect to last page in my template.php:

// This snippet returns the user to their last visited page after they've logged in.
function screen_menu_item_link($link) {
if ($link['title']=='Log In') {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}

//set the destination, for different destinations for different users, work it out here
$destination = drupal_get_destination();

//Merge in the query with current localized options
$link['localized_options'] += array(
'query' => $destination,
);
}
return l($link['title'], $link['href'], $link['localized_options']);
}

Would you be able to tell me, is there a part of the code above that I can place in my current snippet?

tallsimon’s picture

try this
return $_REQUEST['q'];