Email
Share

We Rock Your Web Forum » Content Management Systems » Drupal

Drupal PHP Check User Role?

(2 posts)
  1. DrupalJunkie

    senior member
    Joined: Oct '09
    Posts: 77

    Is there a way to check a user's role using a php snippet in Drupal 6.x? I basically want to redirect the user on login based on their role. I have an "initial signup" role that gets created immediately after signup, and upgraded to "authenticated user" when they confirm their email address (to prevent spam).

    Posted 1 year ago #

  2. Posted 1 year ago
  3. cwd

    senior admin
    Joined: Jul '09
    Posts: 225

    Yes, you can use the following PHP snippet to check a Drupal user's role. Basically this searches the user role array to see if that user has the specified role "initial signup." If it does, then they get redirected to the "registration-success" page. If not (this assumes they're an authenticated user), they get redirected to the "welcome" page.

    global $user;
    if (in_array("initial signup", array_values($user->roles))) {
        return 'registration-success';
    } else { return 'welcome'; }
    Posted 1 year ago #

RSS feed for this topic

Reply

(required)

Allowed markup: BBcode blockquote code em strong ul ol li font strike center u hr.
You can also put code in between backtick ( ` ) characters.