国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

wordpress屏蔽垃圾評論的方法

2024-09-07 00:50:29
字體:
供稿:網(wǎng)友

垃圾評論一般是由機(jī)器發(fā)布了這樣可以導(dǎo)致幾分鐘內(nèi)發(fā)上萬千上萬條垃圾信息了,這些對于我們來講沒有任何作用了,那么要如何來屏蔽這些垃圾評論呢?

大部分垃圾評論都是用自動化軟件來發(fā)的,它會先GET一個頁面,然后再往wp-comments-post.php文件POST內(nèi)容.

例如:"GET /archives/589.html HTTP/1.1" 200 8490

"POST /wp-comments-post.php HTTP/1.1" 302 26

1、使用插件

垃圾評論過濾:Akismet插件

wordpress評論滑動解鎖:myQaptcha插件

發(fā)現(xiàn)效果不好,Akismet雖然能過濾垃圾評論但是阻止不了機(jī)器人提交評論,而且一來就是幾百個連接,VPS負(fù)載直接飆到4點(diǎn)幾,CPU占用率也很高,導(dǎo)致博客打開異常慢,上個月Akismet統(tǒng)計過濾了1,477,296條的垃圾評論怪不得會慢。

myQaptcha安裝后沒有起色,看日志里被繞過了。

2、直接屏蔽IP

網(wǎng)上找了一個類似功能修改下,先看下IP在日志里是第幾個字段,第一個就填$1,第二個就填$2以此類推.

先從日志中過濾出IP,代碼如下:

  1. awk '/wp-comments-post/ { printf $1 " "}' /var/log/httpd/live-in.org-access_log* | sort | uniq -d -c | awk '$1 > 10 {printf $2 " "}' >/tmp/iptables.txt 2>/dev/null 

結(jié)果保存到/tmp/iptables.txt中。

iptables屏蔽,代碼如下:

  1. awk '{system("iptables -I INPUT -s "$0" -j DROP")}' /tmp/iptables.txt 
  2. service iptables save 

將/tmp/iptables.txt內(nèi)的IP添加到iptables中并保存,查看添加的內(nèi)容,代碼如下:

iptables -n -L |less

說明:-n表示不做DNS解析

提示:如果效果不好,直接屏蔽IP段,直接一個php函數(shù),代碼如下:

  1. // 垃圾評論攔截 
  2.   class anti_spam { 
  3.   function anti_spam() { 
  4.   if ( !current_user_can('level_0') ) { 
  5.   add_action('template_redirect', array($this'w_tb'), 1); 
  6.   add_action('init', array($this'gate'), 1); 
  7.   add_action('preprocess_comment', array($this'sink'), 1); 
  8.   } 
  9.   } //m.survivalescaperooms.com 
  10.   function w_tb() { 
  11.   if ( is_singular() ) { 
  12.   ob_start(create_function('$input','return preg_replace("#textarea(.*?)name=(["'])comment(["'])(.+)/textarea>#"
  13.   "textarea$1name=$2w$3$4/textarea>",$input);') ); 
  14.   } 
  15.   } 
  16.   function gate() { 
  17.   if ( !empty($_POST['w']) && empty($_POST['comment']) ) { 
  18.   $_POST['comment'] = $_POST['w']; 
  19.   } else { 
  20.   $request = $_SERVER['REQUEST_URI']; 
  21.   $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '隱瞞'
  22.   $IP = isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] . ' (透過代理)' : $_SERVER["REMOTE_ADDR"]; 
  23.   $way = isset($_POST['w']) ? '手動操作' : '未經(jīng)評論表格'
  24.   $spamcom = isset($_POST['comment']) ? $_POST['comment'] : null
  25.   $_POST['spam_confirmed'] = "請求: ". $request. " 來路: ". $referer. " IP: ". $IP. " 方式: ". $way. " ?熱? ". $spamcom. " -- 記錄成功 --"
  26.   } 
  27.   } 
  28.   function sink( $comment ) { 
  29.   if ( !empty($_POST['spam_confirmed']) ) { 
  30.   if ( in_array( $comment['comment_type'], array('pingback''trackback') ) ) return $comment; 
  31.   //方法一: 直接擋掉, ? die(); 前面兩斜線?h除即可. 
  32.   die(); 
  33.   //方法二: 標(biāo)記為 spam, 留在資料庫檢查是否誤判. 
  34.   //add_filter('pre_comment_approved', create_function('', 'return "spam";')); 
  35.   //$comment['comment_content'] = "[ 小墻判斷這是 Spam! ] ". $_POST['spam_confirmed']; 
  36.   } 
  37.   return $comment; 
  38.   } 
  39.   } 
  40.   $anti_spam = new anti_spam(); 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 佳木斯市| 吴江市| 布拖县| 佛教| 高陵县| 醴陵市| 隆昌县| 车险| 连云港市| 红原县| 吴桥县| 新沂市| 平湖市| 木里| 朝阳区| 禄劝| 印江| 紫云| 贵溪市| 曲靖市| 丰原市| 襄垣县| 沁源县| 昌乐县| 贺兰县| 九龙城区| 萨迦县| 临泉县| 阜阳市| 贺兰县| 武清区| 京山县| 奎屯市| 南川市| 沧源| 潍坊市| 广元市| 饶平县| 五莲县| 西峡县| 泰州市|