Hi,
The IP address which is being tracked seems to be the IP address of the server, whereas it should be the IP address of the user accessing the site.

Comments

star-szr’s picture

Status: Needs work » Active

Setting to active because there is no patch. See http://drupal.org/node/156119 for an explanation of issue statuses.

GBurg’s picture

EDIT: Misread your inital post, I don't have this issue with the server ip being saved instead of user ip.

----------------------------------------------------------------
Initial reply:

Hi,

Wanted to note that in most recent dev version only update of ipadress happens when the user logs out. I don't know why it isn't saved when the user logs in...?

Quick fix: Replace:
in user_stats.module
Replace the following function by the code below:

/**
 * Implements hook_user_login().
 */
function user_stats_user_login(&$edit, $account) {
  if (TRUE && variable_get('user_stats_count_logins', TRUE)) {
    user_stats_login_count_update('increment', $account->uid);
  }
  user_stats_ip_address_update($account->uid, ip_address());
}

Regards,

Geert

naseemAl’s picture

I had a similar problem and found a temporary (i.e., imperfect) solution. I've only been using php for two days now, so take this post with a grain of salt.

Drupal appears to get the IP address by calling the ip_address() function in /includes/bootstrap.inc, which uses the $_SERVER['REMOTE_ADDR'] variable to retrieve the clients IP address.

However, all HTTP requests are forwarded to the webserver I'm using by some proxy, so the $_SERVER['REMOTE_ADDR'] gives the IP address of my servers proxy rather than the client. To get the client's IP I had to instead use the $_SERVER['HTTP_X_FORWARDED"FOR'] variable. Basically, I replaced the entire ip_address() function with the code below. Please note, however, that this is a far from perfect solution (e.g., see http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html). This biggest problem is that, apparently, for people behind a DHCP router, I'll be tracking their local address (e.g., 192.168.X.X for anyone behind a linksys router). Seems to work for clients visiting from university networks, though, which is what I'm most interested in.

If anyone has a better solution that would be great.

ip_address() {
  $ip_address = &drupal_static(__FUNCTION__);

  if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
  } else {
    $ip_address = $_SERVER['REMOTE_ADDR'];
  }

  return $ip_address;
}
Triskelion’s picture

To naseemAl - You might also try uncommenting and configuring the following lines in your settings.php file:

Line 392:
# $conf['reverse_proxy'] = TRUE;
Line 398:
# $conf['reverse_proxy_addresses'] = array('a.b.c.d', ...);

kenorb’s picture

Issue summary: View changes
Related issues: +#2114769: Update boxes patch for 1561196