このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
dokuwiki:plugin:counter [2018/07/02 06:13] – matsui | dokuwiki:plugin:counter [2023/05/24 03:30] (現在) – matsui | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== counter ====== | ||
+ | |||
+ | ===== アクセスカウンター ===== | ||
+ | |||
+ | 今はカウンタプラグインがあって、こっちのほうが便利です。 | ||
+ | [[https:// | ||
+ | |||
+ | accscounterのログディレクトリ | ||
+ | # ll data/ | ||
+ | |||
+ | Proxyなど使っていたりして、X-Forwad-ForからIPを取得する場合 | ||
+ | syntax/ | ||
+ | syntax/ | ||
+ | |||
+ | |||
+ | ------ | ||
+ | [[http:// | ||
+ | |||
+ | ====== lib/ | ||
+ | <code console> | ||
+ | |||
+ | <?php | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | $mode = 1; | ||
+ | // 総カウント用GIF画像のディレクトリ | ||
+ | $all_path = DOKU_BASE.' | ||
+ | // 本日カウント用GIF画像のディレクトリ | ||
+ | $day_path = DOKU_BASE.' | ||
+ | // 昨日カウント用GIF画像のディレクトリ | ||
+ | $yes_path = DOKU_BASE.' | ||
+ | // カウンタ記録ファイル | ||
+ | $log = dirname(__FILE__).'/ | ||
+ | // 昨日カウント数の桁数 | ||
+ | $fig1 = 3; | ||
+ | // 本日カウント数の桁数 | ||
+ | $fig2 = 3; | ||
+ | // 合計カウント数の桁数 | ||
+ | $fig3 = 5; | ||
+ | // 連続IPはカウントしない(yes=1 no=0) | ||
+ | $ipcheck = 1; | ||
+ | // | ||
+ | // | ||
+ | function outhtml($f_cnt, | ||
+ | $size = getimagesize($c_path." | ||
+ | for ($i=0; $i< | ||
+ | $n = substr($f_cnt, | ||
+ | $i_tag.="< | ||
+ | endfor; | ||
+ | |||
+ | return $i_tag; | ||
+ | } | ||
+ | |||
+ | $now_date = gmdate(" | ||
+ | $yes_date = gmdate(" | ||
+ | $dat = file($log); | ||
+ | $ip = $_SERVER[' | ||
+ | |||
+ | // | ||
+ | list($key, $yes, $tod, $all, $addr)=explode(" | ||
+ | |||
+ | if(($ipcheck && $ip != " | ||
+ | if($key == $now_date){// | ||
+ | $tod++; | ||
+ | }else{// | ||
+ | $yes = ($key == $yes_date) ? $tod : 0; | ||
+ | $tod = 1; | ||
+ | } | ||
+ | $all++;// | ||
+ | //更新 | ||
+ | $new = implode(" | ||
+ | $fp = fopen($log, " | ||
+ | flock($fp, LOCK_EX); | ||
+ | fputs($fp, $new); | ||
+ | fclose($fp); | ||
+ | } | ||
+ | // | ||
+ | $yesterday = sprintf(" | ||
+ | $today = sprintf(" | ||
+ | $total = sprintf(" | ||
+ | |||
+ | if($mode){ | ||
+ | // | ||
+ | $yesterday = outhtml($yesterday, | ||
+ | $today = outhtml($today, | ||
+ | $total = outhtml($total, | ||
+ | } | ||
+ | echo " | ||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====== all.datを用意 ====== | ||
+ | counter.phpが書き込みできるよう権限を調整 | ||
+ | <code console> | ||
+ | touch lib/ | ||
+ | </ | ||
+ | |||
+ | ====== 画像の用意 ====== | ||
+ | フォルダ内に、0〜9.gifを設定しておく。 | ||
+ | <code console> | ||
+ | mkdir lib/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ====== テンプレートに出力を記述 ====== | ||
+ | |||
+ | === arctic テンプレート === | ||
+ | |||
+ | 自分は、arcticのテンプレートを使用している為 | ||
+ | lib/ | ||
+ | |||
+ | 最下に下記を記述 | ||
+ | < | ||
+ | <?php include(constant(' | ||
+ | </ | ||
+ | |||
+ | |||
+ | === dokuwiki テンプレート === | ||
+ | |||
+ | <code console> | ||
+ | $ diff -u lib/ | ||
+ | --- lib/ | ||
+ | +++ lib/ | ||
+ | @@ -31,3 +31,4 @@ | ||
+ | |||
+ | <? | ||
+ | | ||
+ | +include(constant(' | ||
+ | </ | ||
+ | |||
+ | === エラー === | ||
+ | |||
+ | DOKU_BASEが空なので、下記のエラーが出てしまう。 | ||
+ | < | ||
+ | [Thu Dec 24 15:31:10 2015] [error] [client xxx.xxx.xxx.xxx] PHP Warning: | ||
+ | [Thu Dec 24 15:31:10 2015] [error] [client xxx.xxx.xxx.xxx] PHP Warning: | ||
+ | [Thu Dec 24 15:31:10 2015] [error] [client xxx.xxx.xxx.xxx] PHP Warning: | ||
+ | </ | ||
+ | |||
+ | == とりあえず下記で対応 == | ||
+ | |||
+ | エラー出なくするだけ | ||
+ | |||
+ | < | ||
+ | # diff counter.php.org counter.php -u | ||
+ | --- counter.php.org 2015-12-24 15: | ||
+ | +++ counter.php 2015-12-24 15: | ||
+ | @@ -22,7 +22,7 @@ | ||
+ | // | ||
+ | // | ||
+ | | ||
+ | - $size = getimagesize($c_path." | ||
+ | + $size = @getimagesize($c_path." | ||
+ | for ($i=0; $i< | ||
+ | $n = substr($f_cnt, | ||
+ | | ||
+ | </ | ||
+ | |||
+ | |||
+ | {{tag> |