简体   繁体   中英

Redirecting a drupal user based on their role

I have a page on my website that I want to redirect users to different pages based on their role.

I tried to make a module to put mymodule_init() to redirect users.

I check with arg(0) my page but cannot figure out how to redirect user based on role.

How do I?

You can access the $user variable since its a global variable by putting

global $user;

At the beginning of your logic. Then you can check the user role with something like:

if (in_array('myrole', $user->roles)) {
  drupal_goto('page');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM