Craig McCoy

Programmer / Developer & Zombie Survivalist

Drupal 6 Redirect User After Login

Dec/2010 30

I needed to redirect my users based on what role they have, and I wanted to share the code with you guys.

You will need a custom module for this example, if you don't currently have one on your install, take a look at my skeleton module example.

We will be using the hook_user hook. (In Drupal 7, this hook has been broken up into several different hooks, but the basic idea is the same.

The $op param in hook_user (in my example I call it $type), explains what action is happening, we want to do something on user login.

In the example below, I want to redirect the users that have a specific role to a custom dashboard, but you could do anything you want.

[[cc lang="php"]
function custommodulename_user($type, & $edit, & $user, $category= NULL) {
if ($type == 'login') {
//check if the user has the parent role
if(in_array("parent user", $user->roles)) {
drupal_goto("/pathtocustom/dashboard");
}
}
}
[[/cc]

Tags: