Display logs summarized by date and host
PLEASE NOTE! The following snippets are user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
(From http://drupal.org/node/46560 .)
This creates a simple table with date, IP, hostname, and user name, if any. Each IP is only shown once per day. This gives you a quick summary of who is visiting your site. It's probably mostly useful to low traffic sites where you know the people who are logging on. If you want to use it on a high traffic site, I recommend deleting the line that fetches the hostname by IP because it's slow.
<?php
$query = "SELECT DATE_FORMAT(FROM_UNIXTIME(timestamp), '%m/%d/%Y') AS visited_on, name, hostname FROM {accesslog} LEFT JOIN {users} ON {accesslog}.uid = {users}.uid GROUP BY hostname, visited_on ORDER BY visited_on DESC, name DESC, hostname ASC";
$result = db_query($query);
$output .= "<table border='1' cellpadding='4'>";
while ($logline = db_fetch_object($result)) {
$output .= "<tr>";
$output .= "<td>" . $logline->visited_on . "</td> " ;
$output .= "<td>" . $logline->hostname . "</td> " ;
$hostname = gethostbyaddr($logline->hostname);
$output .= "<td>" . $hostname . "</td> " ;
$output .= "<td>" . $logline->name . "</td> " ;
$output .= "</tr>";
}
$output .= "</table>";
print $output;
?>