备份:垃圾评论过滤
//Anti-Spam 防止垃圾评论
function lianyue_comment_post( $incoming_comment ) {
$pattern = '/[一-龥]/u';
$http = '/[|サ|ン|グ|ラ|ス|ナ|イ|キ|す|る|こ|と|の|ま|い|計|財|販|ッ|チ|]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match($http, $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match("|nike|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match("|puma|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match("|聘|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match("|jerseys|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match("|index|", $incoming_comment['comment_author_url'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match("|套现|", $incoming_comment['comment_content'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}elseif(preg_match("|赌|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入评论黑名单,本次评论已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除评论限制。");
}
elseif(preg_match("|ritch|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入黑名单,本次访问已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除访问限制。");
}elseif(preg_match("|博彩|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入黑名单,本次访问已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除访问限制。");
}elseif(preg_match("|彩金|", $incoming_comment['comment_author'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入黑名单,本次访问已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除访问限制。");
}elseif(preg_match("|博彩|", $incoming_comment['comment_content'])) {
$myfile = "blacklist.txt" ;
$targetip = $_SERVER['REMOTE_ADDR'] ;
$file_pointer = fopen($myfile, "a") ;
$str = $targetip . "\n" ;
fwrite($file_pointer, $str) ;
fclose($file_pointer) ;
wp_die( "垃圾评论检测:您的IP已被列入黑名单,本次访问已被阻止。若本次垃圾评论检测为误判,请与网站管理员联系以解除访问限制。");
}elseif(preg_match("|http|", $incoming_comment['comment_content'])) {
$spamfile = "numspam.txt";
$fp = fopen($spamfile, "r+");
$spamnum = fread ($fp,10);
$spamnum = $spamnum + 1;
fclose ($fp);
$fp = fopen($spamfile, "w+");
fwrite ($fp,$spamnum);
fclose ($fp);
wp_die( "垃圾评论检测:本次评论已被阻止。");
}elseif(preg_match("|www|", $incoming_comment['comment_content'])) {
$spamfile = "numspam.txt";
$fp = fopen($spamfile, "r+");
$spamnum = fread ($fp,10);
$spamnum = $spamnum + 1;
fclose ($fp);
$fp = fopen($spamfile, "w+");
fwrite ($fp,$spamnum);
fclose ($fp);
wp_die( "垃圾评论检测:本次评论已被阻止。");
}elseif(!preg_match($pattern, $incoming_comment['comment_content'])) {
$spamfile = "numspam.txt";
$fp = fopen($spamfile, "r+");
$spamnum = fread ($fp,10);
$spamnum = $spamnum + 1;
fclose ($fp);
$fp = fopen($spamfile, "w+");
fwrite ($fp,$spamnum);
fclose ($fp);
wp_die( "垃圾评论检测:本次评论已被阻止。");
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'lianyue_comment_post');
评论已关闭