Instead of using one of multiple contributed modules, which deal with redirections from error pages, I'd like to simply redirect users from the pages with other users uids in the path they tried to access to exactly the same pages, but with their own uids.

For example, if a user with uid '3' tried to access a page with the path ssh-keys/user/4/add then she should be redirected to ssh-keys/user/3/add. To achieve the goal I composed the following simple function:

function return_users_page_alter(&$page) {
  // make sure we have 'user' in path.
  if (strpos($current_path, 'user') !== false) { 
    global $user;
    // exclude site team members.
    if (!in_array('administrator', $user->roles) && !in_array('support', $user->roles) && !in_array('billing', $user->roles)) {
        foreach ($path_items as $key => $value) {
          if ($value == 'user') {
            $found_uid = $path_items[$key+1];
        // If user is really different one.
        if ($user->uid != $path_items[$key+1]) {
          $redirect = str_replace($path_items[$key+1], $user->uid, $current_path);

but, unfortunately, it doesn't work. What is wrong with my code?

1 Answer 1


After reading Clive's comments on 7 - drupal_goto() ignores $path if $_GET["destination"] is set?, I've added added unset($_GET['destination']); just before drupal_goto command and it works now fine:

      drupal_goto($external, array('external' => TRUE));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.