/** * @fn last_n_visits * @short Action method that shows the last <em>N</em> hosts that have visited the website. */ public function last_n_visits($n) { $conn = Db::get_connection(); $conn->prepare("SELECT `ip_addr`, `params`, COUNT(*) AS `weight` " . "FROM `visits` " . "GROUP BY CONCAT(`ip_addr`, `user_agent`) " . "ORDER BY `date` DESC " . "LIMIT {1}", $n * 3); $conn->exec(); $this->hosts = array(); if ($conn->num_rows() > 0) { $i = 0; while ($line = $conn->fetch_assoc()) { $host = Geoip::by_ip_addr($line['ip_addr'], $line['params']); $host->weight = $line['weight']; if (!(empty($host->latitude) && empty($host->longitude))) { $this->hosts[] = $host; $i++; } if ($i >= $n) { break; } } } Db::close_connection($conn); $this->render(array('action' => 'hits_by_host')); }