用户上次登录日期 - Drupal

时间:2011-06-24 06:49:21

标签: drupal

在drupal中如何显示用户的上次登录日期和Time.I试用了代码 用户>登录 它显示当前的登录时间,但我希望用户以前的登录时间和日期。

4 个答案:

答案 0 :(得分:1)

看一下User Stats module,它可能适合你。从模块的项目页面:

  

为主题提供常用的用户统计信息,IP地址跟踪和视图   积分。统计数据是:

     
      
  • 注册日期
  •   
  • 加入日期
  •   
  • 自上次登录后的天数
  •   
  • 自上次发布以来的日子
  •   
  • 发布计数
  •   
  • 登录次数
  •   
  • 用户在线/离线
  •   
  • IP地址
  •   

答案 1 :(得分:1)

这些数据与模块Login History

一起保存

答案 2 :(得分:0)

Drupal本身不提供此功能。如果您需要使用它,您可能希望在用户登录时使用序列化的$ user->数据数组(对于$ op =“login”使用hook_user())并在之后保存更新的用户对象,并且然后你就可以在下次登录时获取它。

答案 3 :(得分:0)

我使用的解决方案:跟踪最后两个登录时间戳(当前和前一个)。

/**
 * Implementation of hook_user()
 */
function your_module_user($op, &$edit, &$account, $category = NULL) {
  switch($op) {

    // Successful login
    case 'load':
      // If it's less than two it means we don't have a previous login timtestamp yet.
      $account->custom_last_login = sizeof($account->custom_login_history) < 2 
        ? NULL 
        : array_pop($account->custom_login_history); 
      break;

    case 'login':
      // If it's the first time, we don't have a history
      $login_history = is_array($account->custom_login_history) 
        ? $account->custom_login_history 
        : array();

      // Get rid of the old value.
      if (sizeof($login_history) == 2) {
        array_pop($login_history);
      }

      // Add to the history the current login timestamp.
      array_unshift($login_history, $account->login);

      user_save($account, array('custom_login_history' => $login_history));
      break;
  }
}

然后在您的模板中,您只需使用$user->custom_last_login。如果它是空的,则意味着我们还没有上一个时间戳,将在下次登录后可用。