**2011年4月11日** ====== 続・アクセスカウンター ====== 数日様子見ていい感じに動いているかな?\\ 予想通りの数字の少なさで泣けてくるけど。 ===== クローラー ===== デバッグでログ取って気になったのがYahooとgoogleのクローラーの扱い。\\ BOTなんだからアクセス数から弾くべきなんだろうな~\\ HTTP_USER_AGENT見ればわかるからとりあえず[[http://help.yahoo.com/help/us/ysearch/slurp|Yahoo! Slurp]]と[[http://www.google.com/bot.html|Googlebot]]はノーカウントに。 ===== phpコードとか ===== 元ネタは[[http://www.php-z.net/c5/]] /lib/counter/ にcount.dat、lock.dat、counter.phpを配置。 /lib/images/counter/ に0.gif~9.gif、today.gif、yesterday.gifを配置。 /lib/tpl/arctic/footer.html に呼出しコード追加。 ==== /lib/images/counter/0-9.gif ==== {{blog:2011:counter_number.gif?nolink}}\\ これをバラしたもの。 ==== /lib/counter/counter.php ==== クローラーとadminログインでノーカウント。\\ IPを$ipcheck_max個分保持してその間は重複カウント無し。 $ipcheck_max) array_shift($ip_list); } } // カウントファイル更新 if ($update) { $ip_buf = implode(",", array_values($ip_list)); $buf = implode("|", array($today_date, $yes_count, $today_count, $total_count, $ip_buf)); $fp = fopen($count_file, "w"); fputs($fp, $buf); fclose($fp); } // ロック解除 fclose($fp_lock); // 桁数整形 $yes_count_str = sprintf("%0".$fig1."d", $yes_count); $today_count_str = sprintf("%0".$fig2."d", $today_count); $total_count_str = sprintf("%0".$fig3."d", $total_count); $title = "Total:{$total_count_str} Today:{$today_count_str} Yesterday:{$yes_count_str}"; // タグを取得 $yes_count_str = outhtml($yes_count_str, $yes_counter_path); $today_count_str = outhtml($today_count_str, $today_counter_path); $total_count_str = outhtml($total_count_str, $total_counter_path); $size = getimagesize($today_img_path); $today_img = " \"today\""; $size = getimagesize($yes_img_path); $yes_img = " \"yesterday\""; echo ''.$total_count_str . $today_img . $today_count_str . $yes_img . $yes_count_str.''; } // カウント数とパスを与えて、IMGタグを返す function outhtml($f_cnt,$c_path) { $size = getimagesize($c_path. "0.gif"); // 0.gifからwidthとheight取得 for($i = 0; $i < strlen($f_cnt); $i++) { // 桁数分だけループ $n = substr($f_cnt, $i, 1); // 左から一桁ずつ取得 $i_tag .= "\"{$n}\""; } return $i_tag; } ?> ==== /lib/tpl/arctic/footer.html ==== フッターの一番左に呼出しコードを追加しただけ。
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0
{{tag>php アクセスカウンター}} ~~DISCUSSION~~