search
Homephp教程php手册直接拒绝wordpress黑名单评论的发表

其实伦家不想这么快就发新文章的, 把美丽动人的玉照都顶下去了. 大家知道wordpress黑名单的评论会被自动标记为垃圾评论, 这个做法我感觉挺浪费资源的, 毕竟垃圾评论还是写入了数据库, 如果集中时间段被大量spam攻击, 这种黑名单机制对保护数据库无济于事, 然

其实伦家不想这么快就发新文章的, 把美丽动人的玉照都顶下去了.
大家知道wordpress黑名单的评论会被自动标记为垃圾评论, 这个做法我感觉挺浪费资源的, 毕竟垃圾评论还是写入了数据库, 如果集中时间段被大量spam攻击, 这种黑名单机制对保护数据库无济于事,
然后我写了个函数, 效果是直接拒绝符合黑名单条件的评论发表, 评论不会写入数据库

方法A : 以下代码扔到functions.php

function xhd_fuckspam($comment) {
    if(  is_user_logged_in()){ return $comment;} //登录用户无压力...
    if( wp_blacklist_check($comment['comment_author'],$comment['comment_author_email'],$comment['comment_author_url'], $comment['comment_content'], $comment['comment_author_IP'], $comment['comment_agent'] )){
        header("Content-type: text/html; charset=utf-8");
        exit('草你麻痹垃圾评论滚粗');
    }  else  {
        return $comment; 
    }
} 
add_filter('preprocess_comment', 'xhd_fuckspam');

方法B : 以下代码扔到comments-ajax.php (随便找个地方,比如检查评论太快那段函数后面)

 if( wp_blacklist_check($comment_author,$comment_author_email,$comment_author_url, $comment_content )&&!is_user_logged_in()){//登录用户还是无压力...
        err(__('草你麻痹垃圾评论滚粗'));   
    }

两个方法效果和原理略有不同,

  • 方法A:click submit→POST出去→收到拒绝信息 exit→return→ 会清空评论框内容并重置提交时间间隔 == submit了一次
    优点: 杀毒彻底
  • 方法B:click submit→POST被拒绝→return→ 会保留评论框内容 == 没有submit过
    优点:
    1. 评论者省时省力, 我是用此法来拒绝纯英文评论的, 因为此类误判几率大, 省得好人们重新再评论一次了;
    2. 由于没有POST出去, 所以相对而言对数据库压力最小;

    缺点: 由于comments-ajax是从表单内直接提取$_POST的的字段,所以无法匹配IP和agent类黑名单

效果图:
fuck-spam

可以自行测试, 方法: 把你在这里评论时的昵称改成带bags或者louis的, (这些都已经in_array在小蝴蝶黑名单了) 然后提交评论, 剩下来的你们就自己感受吧
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software