ph-7/notallowed

过滤粗俗用语、用户名、垃圾邮件/临时邮箱等。

2.0.0 2023-01-15 04:44 UTC

This package is auto-updated.

Last update: 2024-09-14 03:54:19 UTC


README

NotAllowed 是一个简单轻量级的 PHP 8.1 库,可以帮助您屏蔽词语、粗俗用语、黑名单 IP、禁止用户名、禁止银行卡号等。

您可以在 ~/src/banned-data/* 文件夹中轻松添加新的特定关键词(如 IP、用户名、银行账户、词语等)进行禁止。

🛠 服务器要求

📓 安装(使用 Composer)

composer require ph-7/notallowed

🎮 使用

简单示例,展示了您可以用它做什么 :)

use PH7\NotAllowed\Ban;

if (Ban::isUsername('admin')) {
    echo '"admin" is not allowed as username.';
}

if (Ban::isEmail('james@spamhole.com')) {
    echo '"@spamhole.com" domain is considered as a email spam host.';
}

if (Ban::isWord('He is an asshole')) {
    echo 'Please watch your mouth :-)';
}

if(Ban::isIp('1.170.36.229')) {
    echo 'This IP address is blacklisted';
}

$userinput = 'admin';
if (Ban::isUsername($userinput, ['root', 'sudo', 'admin'])) {
    echo "$userinput is not allowed";
}

// Validate of the userinput is a banned word _OR_ a banned username
if (Ban::isAny($userinput, email: false, word: true, username: true)) {
    echo "$userinput is not allowed";
}

扩展禁止短语

您可以通过两种方式提供自己的值,与内置的禁止数据合并

  1. Ban::merge(string $scope, string | array $value)
  2. Ban::mergeFile(string $scope, string $path)

$scope 指的是数据的类别。当前可能的值有

  • 用户名
  • 词语
  • IP
  • 电子邮件
  • 银行账户
示例
Ban::merge('usernames', ['pooter', 'hitler', '690']);
Ban::merge('words', ['cuck', 'bomb']);
Ban::mergeFile('emails', './my_banned_emails.txt');

现在按常规约定进行验证

🚀 作者

Pierre-Henry Soria,一位充满激情、禅宗且酷的软件工程师 😊

@phenrysay

Pierre-Henry Soria

👩🏻‍💻 协助者

soulshined - 只是一个程序员

🧐 被使用于...

pH7Builder,一个社交约会网站构建器。在这里使用: https://github.com/pH7Software/pH7-Social-Dating-CMS/blob/master/_protected/framework/Security/Ban/Ban.class.php

⚖️ 许可证

MIT 许可证 下慷慨分发! 🎈