I have a number of different roles on my website. I only want to redirect certain log ins based on their user roles - each role to its individual page (and 4 different roles to one specific page). I'd rather this not be dependant on the uid numbers seeing as future years the specific people will be different uid numbers, but the roles will be the same (seeing as that could be changed easily).

Comments

Alex Regenbogen’s picture

Just subscribing, I wish to accomplish the very same thing....

If I manage to solve it using a snippet for Redirection Condition, I'll post it here...

Update: I've used a PHP snippet for URL destination... I think with a little puzzling you'll be able to tackle your problem as well.

global $user;
if (sizeof($user->roles) > 1) {
//User has more than one role (standard is 1 for an authenticated)
    return 'node/5'; // Custom page for 'special users'
} else {
//User is 'just' an authenticated user.
    return '<front>';
}

The above code works for me, as I have given anonymous users the possibility to register for an account on their own, but in order to gain access to certain area's of the site they need approval from an administrator. (which then gives them additional roles if needed)
A user that registers him/herself gets redirected to the front-page, and any logged in user that has been granted additional rights will get redirected to their 'special' page...

If you we're to go thru the $user-roles, and check if a certain role was present, you will be able to detect and redirect accordingly..

JStarcher’s picture

That's kinda a hacky way of doing it in my opinion. Here is the better way:

global $user;
if (in_array('special users', $user->roles)) {
    return 'node/5'; // Custom page for 'special users'
} else {
    return '<front>'; //User does not have 'special users' role.
}

and of course you can extend that if you want to test for multiple roles and such.

Sakrecoer’s picture

Status: Active » Fixed

Perfect thank you!

And for all the noobs like me out there, here is a translation
replace *special users* with the role name.

to create a different redirection for another specific role, you just need to copy-paste this section of the code:

if (in_array('special users', $user->roles)) {
    return 'node/5'; // Custom page for 'special users'
}

between the previous *if*'s closing } and the *else* thingy....

edit- and of course, paste the snippet in the "URL destination settings" window, not the "Redirection condition settings".

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

geshan’s picture

what do I do if I want to redirect "authenticated users" to the page they logged in from. Meaning if they were viewing a page(or any other content type), say /node/xxx , they click login which will take them to /user but after login I want the "authenticated user" to be redirected to /node/xxx from where s/he logged it. How to I do it?