CWD Forum » Content Management Systems » Drupal

Drupal PHP Check User Role?

(2 posts)
  1. DrupalJunkie

    member
    Joined: Oct '09
    Posts: 26

    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 month ago #
  2. Sponsored Links

    Posted 1 month ago
  3. cwd

    senior admin
    Joined: Jul '09
    Posts: 143

    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 month 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.

485 posts in 187 topics over 14 months by 49 of 96 members. Latest: xiezhen, Markjohn, krocodiled