====== counter ====== ===== アクセスカウンター ===== 今はカウンタプラグインがあって、こっちのほうが便利です。 [[https://www.dokuwiki.org/ja:plugin:accscounter]] accscounterのログディレクトリ # ll data/meta/_accscounter/ Proxyなど使っていたりして、X-Forwad-ForからIPを取得する場合 syntax/counter.php:47: #$clientIP = clientIP(true); syntax/counter.php:48: $clientIP = $_SERVER['HTTP_X_FORWARDED_FOR']; ------ [[http://php.s3.to/counter/|レッツPHP!]]のカウンタをDokuwikiに合わせ調節しました。 ====== lib/counter/counter.php 用意 ====== "; endfor; return $i_tag; } $now_date = gmdate("Ymd", time()+9*3600); // 今日の日付 $yes_date = gmdate("Ymd", time()-15*3600); // 昨日の日付 $dat = file($log); //配列にログ読み込む $ip = $_SERVER['REMOTE_ADDR']; //IPアドレス //変数を展開(比較用日付、昨日、今日、総合、直前IP) list($key, $yes, $tod, $all, $addr)=explode("|", $dat[0]); if(($ipcheck && $ip != "$addr") || $ipcheck==0){ if($key == $now_date){//ログの日付が今日ならカウントアップ $tod++; }else{//日付がかわったら昨日に今日、今日に1を入れる。昨日じゃないなら昨日に0 $yes = ($key == $yes_date) ? $tod : 0; $tod = 1; } $all++;//合計カウントアップ //更新 $new = implode("|", array($now_date,$yes,$tod,$all,$ip)); $fp = fopen($log, "w"); flock($fp, LOCK_EX); fputs($fp, $new); fclose($fp); } //桁数整形 $yesterday = sprintf("%0".$fig1."d", $yes); $today = sprintf("%0".$fig2."d", $tod); $total = sprintf("%0".$fig3."d", $all); if($mode){ //タグを取得(画像出力) $yesterday = outhtml($yesterday, $yes_path); $today = outhtml($today, $day_path); $total = outhtml($total, $all_path); } echo "Yesterday:$yesterday Today:$today Total:$total"; ?> ====== all.datを用意 ====== counter.phpが書き込みできるよう権限を調整 touch lib/counter/all.dat ====== 画像の用意 ====== フォルダ内に、0〜9.gifを設定しておく。 mkdir lib/counter/images ====== テンプレートに出力を記述 ====== === arctic テンプレート === 自分は、arcticのテンプレートを使用している為 lib/tpl/arctic/footer.html 最下に下記を記述 === dokuwiki テンプレート === $ diff -u lib/tpl/dokuwiki/tpl_footer.php.org lib/tpl/dokuwiki/tpl_footer.php --- lib/tpl/dokuwiki/tpl_footer.php.org 2014-12-10 09:49:21.000000000 +0900 +++ lib/tpl/dokuwiki/tpl_footer.php 2014-12-10 09:48:51.000000000 +0900 @@ -31,3 +31,4 @@ === エラー === DOKU_BASEが空なので、下記のエラーが出てしまう。 [Thu Dec 24 15:31:10 2015] [error] [client xxx.xxx.xxx.xxx] PHP Warning: getimagesize(/lib/counter/images/0.gif): failed to open stream: No such file or directory in /var/www/html/lib/counter/counter.php on line 26, referer: http://dokuwiki.fl8.jp/start [Thu Dec 24 15:31:10 2015] [error] [client xxx.xxx.xxx.xxx] PHP Warning: getimagesize(/lib/counter/images/0.gif): failed to open stream: No such file or directory in /var/www/html/lib/counter/counter.php on line 26, referer: http://dokuwiki.fl8.jp/start [Thu Dec 24 15:31:10 2015] [error] [client xxx.xxx.xxx.xxx] PHP Warning: getimagesize(/lib/counter/images/0.gif): failed to open stream: No such file or directory in /var/www/html/lib/counter/counter.php on line 26, referer: http://dokuwiki.fl8.jp/start == とりあえず下記で対応 == エラー出なくするだけ # diff counter.php.org counter.php -u --- counter.php.org 2015-12-24 15:34:07.000000000 +0900 +++ counter.php 2015-12-24 15:32:09.000000000 +0900 @@ -22,7 +22,7 @@ //---------設定ここまで------ //カウント数とパスを与えて、IMGタグを返す function outhtml($f_cnt, $c_path){ - $size = getimagesize($c_path."0.gif"); //0.gifからwidthとheight取得 + $size = @getimagesize($c_path."0.gif"); //0.gifからwidthとheight取得 for ($i=0; $i"; {{tag>dokuwiki}}