\n"; $logs = file("log2.txt"); $agents = array(); $referers = array(); $hosts = array(); foreach ($logs as $l) { $l = rtrim($l); list($agent, $referer, $host) = explode("\t", $l); if ($agent) array_push($agents, $agent); if ($referer) array_push($referers, $referer); if ($host) array_push($hosts, $host); } print_graph($agents, 'ユーザーエージェント', 'blue'); print_graph($referers, 'リファラ', 'green'); print_graph($hosts, 'ホスト(IP)', 'red'); print "\n"; exit(); } $fp = @fopen("counter6.txt", "r+") or die("Counter Error"); flock($fp, LOCK_EX); $count = fgets($fp); $count++; rewind($fp); fputs($fp, $count); fclose($fp); $log = $_SERVER['HTTP_USER_AGENT'] . "\t"; $log .= $_SERVER['HTTP_REFERER'] . "\t"; $log .= @gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n"; $fp = @fopen("log2.txt", "a") or die("Log Error"); flock($fp, LOCK_EX); fputs($fp, $log); fclose($fp); print "$count"; function print_graph($datas, $title, $color) { $ranks = array_count_values($datas); arsort($ranks); print "$title TOP5\n"; print "\n"; $rnum = 1; foreach ($ranks as $k => $v) { $w = $v * 10; print ""; print ""; print ""; print "\n"; $rnum++; if ($rnum > 5) break; } print "
$k"; print ""; print ""; print "
$v 件
\n"; } ?>