Hi I would like to know if is possible to see directly the ip of anonymous users in the statistic log
The module is the default statistic module present in drupal, i should make some changes to the statistic.module, but i don't know whic :( could please someone help me?
Thanks
Filippo

Comments

filartrix’s picture

I found this, that is the place where the ip is stored, in the variable hostname

    // Log this page access.
    db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", strip_tags(drupal_get_title()), $_GET['q'], referer_uri(), $_SERVER['REMOTE_ADDR'], $user->uid, session_id(), timer_read('page'), time());
  }

Now i woul like the hostname variable showed instead of u.name ... but i really don't know how :(

/**
 * Menu callback; presents the "recent hits" page.
 */
function statistics_recent_hits() {
  $header = array(
    array('data' => t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'),
    array('data' => t('Page'), 'field' => 'a.path'),
    array('data' => t('User'), 'field' => 'u.name'),
    array('data' => t('Operations'))
  );

  $sql = 'SELECT a.aid, a.path, a.title, a.uid, u.name, a.timestamp FROM {accesslog} a LEFT JOIN {users} u ON u.uid = a.uid' . tablesort_sql($header);

  $result = pager_query($sql, 30);
  while ($log = db_fetch_object($result)) {
    $rows[] = array(
      array('data' => format_date($log->timestamp, 'small'), 'class' => 'nowrap'),
      _statistics_format_item($log->title, $log->path),
      theme('username', $log),
      l(t('details'), "admin/logs/access/$log->aid"));
  }

  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 30, 0);
  return $output;
}
pol’s picture

Hello,

This is the answer:

function statistics_recent_hits() {
  $header = array(
    array('data' => t('Timestamp'), 'field' => 'a.timestamp', 'sort' => 'desc'),
    array('data' => t('Page'), 'field' => 'a.path'),
    array('data' => t('User'), 'field' => 'u.name'),
    array('data' => t('Hostname'), 'field' => 'a.hostname'),
    array('data' => t('Operations'))
  );

  $sql = 'SELECT a.aid, a.path, a.title, a.uid, a.hostname, u.name, a.timestamp FROM {accesslog} a LEFT JOIN {users} u ON u.uid = a.uid'. tablesort_sql($header);

  $result = pager_query($sql, 30);
  $rows = array();
  while ($log = db_fetch_object($result)) {
    $rows[] = array(
      array('data' => format_date($log->timestamp, 'small'), 'class' => 'nowrap'),
      _statistics_format_item($log->title, $log->path),
      theme('username', $log),check_plain($log->hostname),
      l(t('details'), "admin/reports/access/$log->aid"));
  }

  if (empty($rows)) {
    $rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
  }

  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 30, 0);
  return $output;
}

It seems that this is a very common query, I hope it will be included in D7.

I'm also wondering if it is possible to use a module to hook that function instead of changing drupal core files...