以前、お手軽スパム対策を紹介しましたが、さらに精度(?)をあげたものを公開します。
「お問い合わせ」のスパム対策ですが、モジュール名はcontact。
変更箇所は2カ所。
modules\contact\templates\contact_contactusform.html
modules\contact\index.php
まずは、「contact_contactusform.html」で、
<form name="<{$contactform.name}>"・・・
の下に次の文を追加
<input type="hidden" name="sb_showtime" value="<{php}>echo time();<{/php}>" />
次に「index.php」で、
include "header.php";
の下に次の文を追加
//Spam buster! The post within 3 seconds is invalid.
$sb_timer = time() - $_POST['sb_showtime'];
$sb_min_sec = 3;
$sb_max_sec = 3600;
$sb_html_is_spam = true;
$sb_comment_name = "usersComments";
if( $_POST['submit']){
$sb_spam_flag = false;
if( $sb_timer < $sb_min_sec ) $sb_spam_flag = true;
if( $sb_timer > $sb_max_sec ) $sb_spam_flag = true;
if( $sb_html_is_spam == true ){
if( ereg("^<.*>",$_POST[$sb_comment_name]) ) $sb_spam_flag = true;
}
if( $sb_spam_flag == true){
die;
}
さてと、ちょっと長くなりました。ソースを判りやすくして改造しやすくしました。
設定部分は、次のようになっています。
$sb_min_sec = 3;⇒3秒以下はスパム
$sb_max_sec = 3600;⇒3600秒以上はスパム
$sb_html_is_spam = true;⇒先頭がタグコードつまり'<'ならスパム
$sb_comment_name = "usersComments";⇒POST時の本文にあたるPOST名
今回はコンタクトモジュールでしたが、$_POST['submit']の部分と、設定の部分を弄れば他にも応用できると思います。
まだ時間が足りなくて他への応用がチェックできていないのですが、時間を見つけてUPしてきます。
「このモジュールは、こうしたらうまく言った!」って報告が有れば、是非お願いします。
複数集まるようでしたら、専用ページを作って管理しようかと思います。