Пример #1
0
function log_user_ip($userId)
{
    if (!$userId) {
        message_error('No user ID was supplied to the IP logging function');
    }
    $time = time();
    $ip = get_ip(true);
    $entry = db_select_one('ip_log', array('id', 'times_used'), array('user_id' => $userId, 'ip' => $ip));
    // if the user has logged in with this IP previously
    if ($entry['id']) {
        db_query_fetch_none('
            UPDATE ip_log SET
               last_used=UNIX_TIMESTAMP(),
               ip=:ip,
               times_used=times_used+1
            WHERE id=:id', array('ip' => $ip, 'id' => $entry['id']));
    } else {
        db_insert('ip_log', array('added' => $time, 'last_used' => $time, 'user_id' => $userId, 'ip' => $ip));
    }
}
Пример #2
0
function log_user_ip($user_id)
{
    validate_id($user_id);
    $now = time();
    $ip = get_ip(true);
    $entry = db_select_one('ip_log', array('id', 'times_used'), array('user_id' => $user_id, 'ip' => $ip));
    // if the user has logged in with this IP previously
    if ($entry['id']) {
        db_query_fetch_none('
            UPDATE ip_log SET
               last_used=UNIX_TIMESTAMP(),
               ip=:ip,
               times_used=times_used+1
            WHERE id=:id', array('ip' => $ip, 'id' => $entry['id']));
    } else {
        db_insert('ip_log', array('added' => $now, 'last_used' => $now, 'user_id' => $user_id, 'ip' => $ip));
    }
}