ph-7 / notallowed
Filter profane words, usernames, spam/temporary emails, etc.
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^9.5
README
NotAllowed is a simple lightweight PHP 8.1 library that helps you to censor words, profane words, blacklisted IPs, forbidden user names, banned bank card numbers, etc.
You can add easily new specific keywords (such as IPs, usernames, bank accounts, words, etc) to ban in ~/src/banned-data/*
folder.
🛠 Server Requirement
- PHP 8.1 or higher.
📓 Installation (with Composer)
composer require ph-7/notallowed
🎮 Usage
Simple example of what you can do with it :)
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"; }
Extending Banned Phrases
You can supply your own values to be merged with the out-of-box banned-data 2 ways
Ban::merge(string $scope, string | array $value)
Ban::mergeFile(string $scope, string $path)
$scope
refers to the category of data. Possible values are currently:
- usernames
- words
- ips
- emails
- bank_accounts
Example
Ban::merge('usernames', ['pooter', 'hitler', '690']); Ban::merge('words', ['cuck', 'bomb']); Ban::mergeFile('emails', './my_banned_emails.txt');
Now simply validate per normal conventions
🚀 Author
Pierre-Henry Soria, a highly passionate, zen & cool software engineer 😊
👩🏻💻 Helpers
soulshined - just a coder
🧐 Used By...
pH7Builder, a social dating webapp builder. Used here: https://github.com/pH7Software/pH7-Social-Dating-CMS/blob/master/_protected/framework/Security/Ban/Ban.class.php.
⚖️ License
Generously distributed under MIT License! 🎈