You are here

function user_stats_ip_address_update in User Stats 6

Same name and namespace in other branches
  1. 5 user_stats.module \user_stats_ip_address_update()
  2. 7 user_stats.module \user_stats_ip_address_update()

Update the IP address of a given user.

The IP address is not updated if it is the same as the last recorded IP, however, if the user has IP address A, then switches to IP address B and back to A again, A will be recorded twice. This is to keep an accurate log of IP addresses used by users.

Parameters

$uid: User ID of user who's IP is being updated.

$ip_address: IP address to assign to user.

3 calls to user_stats_ip_address_update()
user_stats_comment in ./user_stats.module
Implementation of hook_comment().
user_stats_nodeapi in ./user_stats.module
Implementation of hook_nodeapi().
user_stats_user in ./user_stats.module
Implementation of hook_user().

File

./user_stats.module, line 839
User Stats provides commonly requested user statistics for themers. These are:

Code

function user_stats_ip_address_update($uid, $ip_address) {
  if (!is_numeric($uid)) {
    return;
  }

  // Don't bother recording IPs of anonymous users, and don't record any
  // addresses if the config form tells us not to.
  if ($uid == 0 || !variable_get('user_stats_track_ips', TRUE)) {
    return;
  }
  $query = db_query_range("SELECT ip_address\n    FROM {user_stats_ips} WHERE uid = %d\n    ORDER BY first_seen_timestamp DESC", $uid, 0, 1);
  if ($ip_address != db_result($query)) {

    // Reset internal cache.
    user_stats_cache_set('reset', $uid);
    db_query("INSERT INTO {user_stats_ips} (uid, ip_address, first_seen_timestamp)\n      VALUES (%d, '%s', %d)", $uid, $ip_address, time());

    // Allow modules to react to an IP address change.
    module_invoke_all('user_stats', 'ip_address', 'insert', $uid, $ip_address);
  }
}