在Drupal 7登录后重定向

时间:2014-01-22 16:05:03

标签: php redirect drupal drupal-7 ldap

我正在尝试让用户在登录后返回他们所在的页面。现在,它将它们带到当前页面。我正在登录我的大学LDAP,所以drupal模块不起作用。这是我的user.module代码,它将用户带到lpad登录而不是drupal登录块:

function user_login($form, &$form_state) {
  global $user;

  // If we are already logged on, go to the user page instead.
  if ($user->uid) {
    drupal_goto('user/' . $user->uid);
  }
  header("Location: https://www.cvrc.virginia.edu/login/pc"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
  // Display login form:
  $form['name'] = array('#type' => 'textfield',
    '#title' => t('Username'),
    '#size' => 60,
    '#maxlength' => USERNAME_MAX_LENGTH,
    '#required' => TRUE,
  );

  $form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
  $form['pass'] = array('#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('Enter the password that accompanies your username.'),
    '#required' => TRUE,
  );
  $form['#validate'] = user_login_default_validators();
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));

  return $form;
}

有什么想法?感谢。

2 个答案:

答案 0 :(得分:0)

(如果我理解的话)。想一想,您需要使用$_SERVER["HTTP_REFERER"]来返回用户。试试吧:

drupal_goto($_SERVER["HTTP_REFERER"]);

答案 1 :(得分:-1)

首先代替

    if ($user->uid) {
    drupal_goto('user/' . $user->uid);
  }

用户user_is_logged_in()或$ user-> uid> 0。您当前的逻辑也适用于uid 0的匿名用户

从表面看来,表单的代码永远不会被执行。

如果您在登录后尝试重定向用户,我相信您应该这样做

// If we are already logged on, go to the user page instead.
  if (user_is_logged_in()) {
    drupal_goto('user/' . $user->uid);
  }else{
      // Display login form:
  $form['name'] = array('#type' => 'textfield',
    '#title' => t('Username'),
    '#size' => 60,
    '#maxlength' => USERNAME_MAX_LENGTH,
    '#required' => TRUE,
  );

  $form['name']['#description'] = t('Enter your @s username.', array('@s' => variable_get('site_name', 'Drupal')));
  $form['pass'] = array('#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('Enter the password that accompanies your username.'),
    '#required' => TRUE,
  );
  $form['#validate'] = user_login_default_validators();
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));

  return $form;
  }
 {pseudocode on success form redirect }
  header("Location: https://www.cvrc.virginia.edu/login/pc"); /* Redirect browser */
  /* Make sure that code below does not get executed when we redirect. */
  exit;

类似的东西