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.
======= Add new comment =======
======= Add new comment =======
Comments
===== Commented by Anonymous on 26 April 2007 =====
Will this snippet work with Drupal 4.7.0
Thanx
===== Commented by Alex@vo1dmain on 27 April 2007 =====
I think that will work in previous versions of Drupal, as it hasn't improved far in statistics.
===== Commented by Anonymous on 06 December 2008 =====
Thanks. This worked very well and was easy to implement.
===== Commented by Anonymous on 07 December 2008 =====
There is a slight problem with this I found out. It is adding something at the top of the page before any of my html that is causing it to push down my html about 20px or so. My guess is a space or something but I sure can't find it or figure out exactly what is causing it.
It's definitely threre though in IE, Firefox and Chrome.
===== Commented by Kris on 08 May 2009 =====
Thanks alot for this snippet !
===== Commented by Anonymous on 15 September 2009 =====
I am going to give it a try thanks!