You are here

function login_history_user in Login History 6

Implements hook_user().

File

./login_history.module, line 6

Code

function login_history_user($op, &$edit, &$account) {
  if ($op == 'login') {

    // Is this a one-time login?
    $request_array = explode('/', $_GET['q']);
    if ($request_array[0] == 'user' && isset($request_array[1]) && $request_array[1] == 'reset' && $request_array[5] == 'login') {
      $one_time = 1;
    }
    else {
      $one_time = 0;
    }

    // Now save the user's current login timestamp to login_history.
    $user_agent = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
    db_query("INSERT INTO {login_history} (uid, login, hostname, one_time, user_agent) VALUES (%d, %d, '%s', %d, '%s')", $account->uid, $account->login, ip_address(), $one_time, $user_agent);
  }
}