function user_stats_ip_address_update in User Stats 7
Same name and namespace in other branches
- 5 user_stats.module \user_stats_ip_address_update()
- 6 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.
6 calls to user_stats_ip_address_update()
- user_stats_comment_insert in ./
user_stats.module - Implements hook_comment_insert().
- user_stats_node_insert in ./
user_stats.module - Implements hook_node_insert().
- user_stats_node_update in ./
user_stats.module - Implements hook_node_update().
- user_stats_user_insert in ./
user_stats.module - Implements hook_user_insert to record ip of new user on registration.
- user_stats_user_login in ./
user_stats.module - Implements hook_user_login().
File
- ./
user_stats.module, line 903 - 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}\n WHERE uid = :uid\n ORDER BY first_seen_timestamp DESC", 0, 1, array(
':uid' => $uid,
));
if ($ip_address != $query
->fetchField()) {
// Reset internal cache.
user_stats_cache_set('reset', $uid);
$id = db_insert('user_stats_ips')
->fields(array(
'uid' => $uid,
'ip_address' => $ip_address,
'first_seen_timestamp' => REQUEST_TIME,
))
->execute();
// Allow modules to react to an IP address change.
module_invoke_all('user_stats', 'ip_address', 'insert', $uid, $ip_address);
}
}