How can I redirect only users with a specific role to the admin page when they login ?
Asked
Active
Viewed 1,700 times
1
-
possible duplicate of [How to redirect user to a specific page after they login if they belong to a certain role?](http://stackoverflow.com/questions/3429767/how-to-redirect-user-to-a-specific-page-after-they-login-if-they-belong-to-a-cert) – Henrik Opel Nov 14 '10 at 11:23
1 Answers
2
Well, you need to get the global $user variable. And then check if the user has the desired role, (in this case I assumed the desired role is 'authenticated user'), and the current page is not the admin page (so you don't get a redirection problem), then redirect him to the admin page, or a page of your choice inside drupal_goto('admin');
There you go:
<?php
global $user;
if(in_array('authenticated user', $user->roles) && arg(0) != 'admin') {
drupal_goto('admin');
}
?>
Mohammed J. Razem
- 342
- 1
- 4
- 19
-
1this works but I highly recommend using the Login Destination module instead: http://drupal.org/project/login_destination – Alex Weber Nov 18 '10 at 23:45