読書記録ChangeLog

日記内を検索 / / / ランダム RSS

2007-05-22 / 計算問題によるコメントスパム対策の実装 /

http://www.kagami.org/diary/2007-04-30-1.html
仕込んだ。
簡単だこりゃ。

(1)kuttukibbs.confファイルの$page_template_defaultの
投稿ボタンの前あたりに計算式を追加

      <div class="textarea">
コメント:<textarea name="body" cols="60" rows="5"></textarea>
      </div>
+       <div class="arith"><br>
  +       コメントスパム回避のため,以下の足し算の答えを半角でご記入下さい: <br>
  +       $arith_x + $arith_y = <input class="field" name="arith" value="">
  +       <input type="hidden" name="arith_x" value="$arith_x">
  +       <input type="hidden" name="arith_y" value="$arith_y">
  +     </div>
      <div class="button">
<input type="submit" name="comment" value="投稿">
      </div>

(2)テキトーな場所で計算問題を作成して
### 表示
for (my $i = $latest_id; $i >= 0; $i--) {
    next unless defined $com_hash{$i};
    $comments .= make_comment_html($com_hash{$i}, $i + 1);
}
+ ### スパム防止計算問題の種
+ my $arith_x = int(rand(9)) + 1;
+ my $arith_y = int(rand(9)) + 1;

(3)書き込み時に答え合わせを行う。
### 書き込み
if ($mode eq "write") {
  +   ### 計算の答え合わせ
  +   my $arith = $q->param('arith');
  +   my $arith_x = $q->param('arith_x');
  +   my $arith_y = $q->param('arith_y');
  +   if (!$arith || $arith != $arith_x + $arith_y) {
  +     exit;
  +   }
追記:[2007-05-28]時点で、順調に動いています。
追記:[2007-06-22]時点で、順調に動いています。
追記:[2007-07-21]時点で、順調に動いています。

固定リンク [2007-05-22-3] このエントリーをはてなブックマークに追加 MM/memo投稿

[ コメント |

これまでの訪問者は 人です。