关于如何对付wordpress的垃圾广告机器人

wordpress 是个广为流行的博客系统,也正应为用户之多,随之而来的垃圾广告也越来越多。

曾装过几个反垃圾广告的插件都不怎么理想(包括图片验证码的也无效,设计有漏洞),后来通过日志分析用iptable屏蔽IP段能堵住大部分广告机器人,不过还是要时常填补机器人IP到iptable,操作起来不方便。

机器人是模拟浏览器请求的软件,有伪装的header   user-agent,不容易同正常请求区分开来,所以通过这些参数没有有效的屏蔽办法。

机器人软件模拟浏览器请求有个缺陷就是不会执行页面JS脚本。

通过这个便有了简单的解决方式:

两个文件中加几行代码

第一个文件:wp-includes/comment-template.php

找到 <form action=”<?php echo site_url( ‘/wp-comments-post.php’ ); ?>  发评论的form

form里增加一个隐藏字段

 <input name="ad_flag" id="ad_flag"  type="hidden" value="p"/>

机器人不笨会解析到这个字段并提交请求的时候会带上它

还需要在加上一段JS

<script type="text/javascript">
            jQuery(document).ready(function () {
                jQuery('#commentform').submit(function () {
                jQuery('#ad_flag').attr('name','is_person');
                    });
            });
        </script>

这段代码真实浏览器会解析执行,功能是在提交表单时修改上面那个隐藏字段的name,机器人的话就不会执行这段JS脚本,这就方便在下一步做屏蔽了

文件:wp-comments-post.php

 

if ( !isset($_POST['is_person']) ) {
        header('Allow: POST');
        header('HTTP/1.1 405 Method Not Allowed');
        header('Content-Type: text/plain');
        exit;
}

如果没有is_person 就是垃圾广告机器人,直接屏蔽掉,从此清静了

30 Comments

  1. bayi ga mau makan

    Hey there! I’ve been reading your website for some time now
    and finally got the bravery to go ahead and give you a shout out from
    Porter Texas! Just wanted to say keep up the great work!

    Reply
  2. Travel International

    Hi my loved one! I wish to say that this article is awesome, nice written and include almost all significant infos. I would like to see extra posts like this.

    Reply
  3. Education

    Thanks for every one of your work on this site. Debby loves managing investigations and it’s simple to grasp why. Most of us hear all concerning the powerful form you deliver priceless thoughts through this web site and therefore strongly encourage contribution from other people on this topic while my child is without a doubt starting to learn a lot. Take advantage of the rest of the year. You are conducting a useful job.

    Reply
  4. Education

    Thanks for sharing superb informations. Your website is very cool. I am impressed by the details that you have on this blog. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the information I already searched all over the place and just couldn’t come across. What a perfect website.

    Reply
  5. Education

    Absolutely composed subject matter, regards for information. “The earth was made round so we would not see too far down the road.” by Karen Blixen.

    Reply
  6. Education

    Hiya very cool blog!! Man .. Beautiful .. Superb .. I will bookmark your web site and take the feeds also…I’m satisfied to find a lot of useful information right here within the put up, we’d like work out more strategies on this regard, thank you for sharing.

    Reply
  7. Education

    Utterly indited content, thanks for information. “He who establishes his argument by noise and command shows that his reason is weak.” by Michel de Montaigne.

    Reply
  8. computer tech support

    I do not know if it’s just me or if everybody else encountering issues with your blog. It appears as though some of the text within your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them too? This could be a problem with my web browser because I’ve had this happen previously. Kudos

    Reply
  9. Business & Finance

    Hello.This article was extremely motivating, especially since I was searching for thoughts on this issue last Thursday.

    Reply
  10. Public Health

    You made a few fine points there. I did a search on the subject matter and found most persons will consent with your blog.

    Reply
  11. Education and Training

    Its excellent as your other content : D, regards for posting . “Music is the soul of language.” by Max Heindel.

    Reply
  12. Car & Automotive

    I’m so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that is at the other blogs. Appreciate your sharing this greatest doc.

    Reply
  13. Education and Training

    hi!,I like your writing very a lot! percentage we keep up a correspondence more approximately your article on AOL? I require a specialist on this house to unravel my problem. Maybe that is you! Having a look forward to see you.

    Reply
  14. Education and Training

    It¡¦s really a nice and useful piece of information. I¡¦m glad that you simply shared this useful information with us. Please keep us up to date like this. Thanks for sharing.

    Reply
  15. Travel International

    We are a group of volunteers and opening a new scheme in our community. Your website provided us with valuable info to work on. You’ve done a formidable job and our entire community will be thankful to you.

    Reply
  16. masakan anak 2 tahun

    constantly i used to read smaller content which also clear their motive, and that is
    also happening with this paragraph which I am reading here.

    Reply
  17. Car & Automotive

    wonderful points altogether, you just gained a brand new reader. What might you recommend in regards to your submit that you simply made a few days ago? Any certain?

    Reply
  18. Pingback: social signals seo 2015

  19. Pingback: best backyard zip line suppliers

  20. Pingback: waterproofing

  21. Pingback: cara pendaftaran cpns

  22. Pingback: pemandangan

  23. Pingback: Invitro Pharamacology Services

  24. Pingback: straight from the source

  25. Pingback: Sistem Klinik

  26. Pingback: cosmetic dental tooth implant Boynton Beach Forida

  27. Pingback: website

  28. Pingback: SEO services in chandigarh

  29. Pingback: http://www.rugscheap.org

  30. Pingback: mondo sonoro

Leave a Comment

电子邮件地址不会被公开。 必填项已用*标注