WordPress實(shí)現(xiàn)自動(dòng)拒絕垃圾評(píng)論的方法
發(fā)布時(shí)間:2014-06-24 16:58:48 作者:佚名
我要評(píng)論

很多WordPress站長(zhǎng)都飽受垃圾評(píng)論的自擾,苦不堪言。這篇文章主要為大家介紹了WordPress實(shí)現(xiàn)自動(dòng)拒絕垃圾評(píng)論的方法,需要的朋友可以參考下
很多WordPress站長(zhǎng)都經(jīng)常受到垃圾評(píng)論的滋擾,針對(duì)這種情況,采用下面的代碼可能會(huì)對(duì)你有所幫助。
將以下代碼加入到functions.php頁(yè)面中。
使用時(shí)任何包含在$bad_comment_content數(shù)組內(nèi)的字符,都將會(huì)被自動(dòng)拒絕留言。
復(fù)制代碼
代碼如下:function in_comment_post_like($string, $array) {
foreach($array as $ref) { if(strstr($string, $ref)) { return true; } }
return false;
}
function drop_bad_comments() {
if (!empty($_POST['comment'])) {
$post_comment_content = $_POST['comment'];
$lower_case_comment = strtolower($_POST['comment']);
$bad_comment_content = array(
'viagra',
'hydrocodone',
'hair loss',
'xanax',
'tramadol',
'russian girls',
'russian brides',
'lorazepam',
'adderall',
'dexadrine',
'no prescription',
'oxycontin',
'without a prescription',
'sex pics',
'family incest',
'online casinos',
'online dating',
'cialis',
'best forex',
'amoxicillin'
);
if (in_comment_post_like($lower_case_comment, $bad_comment_content)) {
$comment_box_text = wordwrap(trim($post_comment_content), 80, "\n ", true);
$txtdrop = fopen('/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt', 'a');
fwrite($txtdrop, " --------------\n [COMMENT] = " . $post_comment_content . "\n --------------\n");
fwrite($txtdrop, " [SOURCE_IP] = " . $_SERVER['REMOTE_ADDR'] . " @ " . date("F j, Y, g:i a") . "\n");
fwrite($txtdrop, " [USERAGENT] = " . $_SERVER['HTTP_USER_AGENT'] . "\n");
fwrite($txtdrop, " [REFERER ] = " . $_SERVER['HTTP_REFERER'] . "\n");
fwrite($txtdrop, " [FILE_NAME] = " . $_SERVER['SCRIPT_NAME'] . " - [REQ_URI] = " . $_SERVER['REQUEST_URI'] . "\n");
fwrite($txtdrop, '--------------**********------------------'."\n");
header("HTTP/1.1 406 Not Acceptable");
header("Status: 406 Not Acceptable");
header("Connection: Close");
wp_die( __('bang bang.') );
}
}
}
add_action('init', 'drop_bad_comments');
foreach($array as $ref) { if(strstr($string, $ref)) { return true; } }
return false;
}
function drop_bad_comments() {
if (!empty($_POST['comment'])) {
$post_comment_content = $_POST['comment'];
$lower_case_comment = strtolower($_POST['comment']);
$bad_comment_content = array(
'viagra',
'hydrocodone',
'hair loss',
'xanax',
'tramadol',
'russian girls',
'russian brides',
'lorazepam',
'adderall',
'dexadrine',
'no prescription',
'oxycontin',
'without a prescription',
'sex pics',
'family incest',
'online casinos',
'online dating',
'cialis',
'best forex',
'amoxicillin'
);
if (in_comment_post_like($lower_case_comment, $bad_comment_content)) {
$comment_box_text = wordwrap(trim($post_comment_content), 80, "\n ", true);
$txtdrop = fopen('/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt', 'a');
fwrite($txtdrop, " --------------\n [COMMENT] = " . $post_comment_content . "\n --------------\n");
fwrite($txtdrop, " [SOURCE_IP] = " . $_SERVER['REMOTE_ADDR'] . " @ " . date("F j, Y, g:i a") . "\n");
fwrite($txtdrop, " [USERAGENT] = " . $_SERVER['HTTP_USER_AGENT'] . "\n");
fwrite($txtdrop, " [REFERER ] = " . $_SERVER['HTTP_REFERER'] . "\n");
fwrite($txtdrop, " [FILE_NAME] = " . $_SERVER['SCRIPT_NAME'] . " - [REQ_URI] = " . $_SERVER['REQUEST_URI'] . "\n");
fwrite($txtdrop, '--------------**********------------------'."\n");
header("HTTP/1.1 406 Not Acceptable");
header("Status: 406 Not Acceptable");
header("Connection: Close");
wp_die( __('bang bang.') );
}
}
}
add_action('init', 'drop_bad_comments');
相關(guān)文章
Clickchina點(diǎn)擊式防垃圾評(píng)論wordpress插件 v1.02
Clickchina是一款模仿Clickcha開(kāi)發(fā)的“點(diǎn)擊式防垃圾評(píng)論wordpress插件”可以有效防止垃圾評(píng)論、防止機(jī)器人自動(dòng)提交評(píng)論,凈化博客。2011-07-26php AntiSpam Typecho 防垃圾評(píng)論插件
如果僅使用antispam插件,可以減少用戶(hù)輸入驗(yàn)證碼的操作,改善訪客體驗(yàn)。2011-06-11百度官方推出的WordPress結(jié)構(gòu)化數(shù)據(jù)插件百度sitemap
這篇文章主要為大家介紹了WordPress結(jié)構(gòu)化數(shù)據(jù)插件百度sitemap,需要的朋友可以參考下2014-06-24WordPress站點(diǎn)實(shí)現(xiàn)分類(lèi)目錄訂閱功能實(shí)例
這篇文章主要為大家介紹了WordPress站點(diǎn)實(shí)現(xiàn)分類(lèi)目錄訂閱功能的方法,需要的朋友可以參考下2014-06-24wordpress設(shè)置友情鏈接只在首頁(yè)顯示的方法
這篇文章主要介紹了wordpress設(shè)置友情鏈接只在首頁(yè)顯示的方法,需要的朋友可以參考下2014-05-08