Enhancing the drupal statistics: ip geolocation
Note committed on 20 August 2007, tagged drupal, module
Drupal statistics logs every access to a page. It is kind-of useful when the user is logged in, but there are times when you want to see where the user physically comes from. For this situation you can just go into "details" and see his ip address. Copy and paste it into some kind of online ip2location service and see the results.
This code allows you to shorten that cycle to just one click.
Here we will enhance the statistics page, providing link to a ip2location free service
open the statistics.module and find the statistics_recent_hits function. The changes in code are marked bold
....
$sql = 'SELECT a.aid, a.path, a.title, a.uid, u.name, a.timestamp<b>, a.hostname</b> 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)<strong>.", ". l(check_plain($log->hostname), "http://www.ip2location.com/$log->hostname")</strong>,
l(t('details'), "admin/logs/access/$log->aid"));
}
...
after that you will have clickable ip address in the username column.
======= 6 comments =======