カテゴリ | |
---|---|
サマリ | voteの連続投票を制限したい |
バージョン | 1.4.7 |
投稿者 | いっつ |
状態 | 質問 |
投稿日 | 2008-05-11 (日) 15:29:08 |
voteを使ってアンケートを採っていますが、同一IPアドレスから連続で投票されてしまいます。
同一IPアドレスからは1時間に1回とかの制限を付けたいのですが、何か方法はありませんか。
一つのページにvoteは複数あるので、それぞれのアンケートに1回ずつなら連続してできる必要があります。
以下のパッチを作って解決しました。
はじめてPHPをさわったので、おかしなところがあったら指摘をお願いします。
*** vote.inc.php.org 2006-10-22 05:40:26.000000000 +0900 --- vote.inc.php 2008-05-11 17:39:23.000000000 +0900 *************** *** 8,19 **** { global $vars, $script, $cols,$rows; global $_title_collided, $_msg_collided, $_title_updated; ! global $_vote_plugin_votes; if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing'); $postdata_old = get_source($vars['refer']); $vote_no = 0; $title = $body = $postdata = $postdata_input = $vote_str = ''; $matches = array(); --- 8,20 ---- { global $vars, $script, $cols,$rows; global $_title_collided, $_msg_collided, $_title_updated; ! global $_vote_plugin_votes, $_vote_plugin_continue; if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing'); $postdata_old = get_source($vars['refer']); + $vote_err = 0; $vote_no = 0; $title = $body = $postdata = $postdata_input = $vote_str = ''; $matches = array(); *************** *** 34,41 **** $cnt = $matches[2]; } $e_arg = encode($arg); ! if (! empty($vars['vote_' . $e_arg]) && $vars['vote_' . $e_arg] == $_vote_plugin_votes) ! ++$cnt; $votes[] = $arg . '[' . $cnt . ']'; } --- 35,48 ---- $cnt = $matches[2]; } $e_arg = encode($arg); ! if (! empty($vars['vote_' . $e_arg]) && $vars['vote_' . $e_arg] == $_vote_plugin_votes) { ! if(local_vote_ipcheck($vote_no)){ ! ++$cnt; ! } ! else{ ! $vote_err = 1; ! } ! } $votes[] = $arg . '[' . $cnt . ']'; } *************** *** 45,50 **** --- 52,61 ---- $postdata .= $vote_str; } + if($vote_err == 1){ + return array('msg'=>$_vote_plugin_continue); + } + if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) { $title = $_title_collided; *************** *** 147,150 **** --- 158,199 ---- return $body; } + + function local_vote_ipcheck($vote_no) + { + $vote_keeptime = 86400; // IIPアドレスを保存する秒数 + + global $vars; + + $ipcheck = 1; + $file = PLUGIN_DIR . 'vote/' . encode($vars['refer']); + $fp = fopen($file, file_exists($file) ? 'r+' : 'w+') + or die("vote.inc.php: Cannot open $file"); + set_file_buffer($fp, 0); + flock($fp, LOCK_EX); + rewind($fp); + $list = array(); + while(!feof($fp)){ + $line = fgets($fp, 256); + $tok = split(',', rtrim($line)); + if($tok[0] < UTIME - $vote_keeptime){ + continue; + } + if(strcmp($tok[1], $_SERVER['REMOTE_ADDR']) == 0 + && $tok[2] == $vote_no){ + $ipcheck = 0; + } + else{ + array_push($list, $line); + } + } + array_push($list, UTIME.",".$_SERVER['REMOTE_ADDR'].",$vote_no\n"); + rewind($fp); + ftruncate($fp, 0); + foreach ($list as $line){ + fputs($fp, $line); + } + fclose($fp); + return $ipcheck; + } ?>
*** ja.lng.php.org 2008-05-11 17:46:22.000000000 +0900 --- ja.lng.php 2008-05-11 17:41:08.000000000 +0900 *************** *** 437,442 **** --- 437,443 ---- // vote.inc.php $_vote_plugin_choice = '選択肢'; $_vote_plugin_votes = '投票'; + $_vote_plugin_continue = '連続投票はできません。'; /////////////////////////////////////// // yetlist.inc.php