diff --git a/sites/all/modules/contrib/user_stats/user_stats.install b/sites/all/modules/contrib/user_stats/user_stats.install index f8ab6d7..40a6585 100644 --- a/sites/all/modules/contrib/user_stats/user_stats.install +++ b/sites/all/modules/contrib/user_stats/user_stats.install @@ -52,7 +52,7 @@ ), 'ip_address' => array( 'type' => 'varchar', - 'length' => 40, + 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => "The user's IP address.", @@ -102,3 +102,18 @@ ); db_change_field('user_stats_ips', 'ip_address', 'ip_address', $ip_address); } + +/** + * Expands the width of the field table to 128; + * it's good enough for 3 IPv6 adresses (ip_address() can return more than one IP). + */ +function user_stats_update_7104(&$sandbox) { + $ip_address = array( + 'type' => 'varchar', + 'length' => 128, + 'not null' => TRUE, + 'default' => '', + 'description' => "The user's IP address.", + ); + db_change_field('user_stats_ips', 'ip_address', 'ip_address', $ip_address); +} diff --git a/sites/all/modules/contrib/user_stats/user_stats.module b/sites/all/modules/contrib/user_stats/user_stats.module index 489bb30..39b5c3b 100644 --- a/sites/all/modules/contrib/user_stats/user_stats.module +++ b/sites/all/modules/contrib/user_stats/user_stats.module @@ -901,6 +901,8 @@ * IP address to assign to user. */ function user_stats_ip_address_update($uid, $ip_address) { + $max_ip_length = 128; + if (!is_numeric($uid)) { return; } @@ -910,6 +912,12 @@ if ($uid == 0 || !variable_get('user_stats_track_ips', TRUE)) { return; } + + if (strlen($ip_address) > $max_ip_length) { + $ip_address = substr($ip_address, 0, $max_ip_length); + $ip_address = substr($ip_address, 0, strrpos($ip_address, ",")); + } + $query = db_query_range("SELECT ip_address FROM {user_stats_ips} WHERE uid = :uid