Hey guys I was just wondering if anyone had made something so usernames containing a word like "fuck" would be denied to register?
Hey guys I was just wondering if anyone had made something so usernames containing a word like "fuck" would be denied to register?
Add this to your register in php.
PHP Code:if(strpos($_POST["username"], 'fuck') !== false)
{
echo '<script>alert("You may not use that username!");</script>';
}
I'm using RevCMS tho :P
Better option:
Code:$entered_name = strtolower($_POST["username"]); $bannedNameParts = array('fuck', 'cunt', 'shit', 'anal', 'ragezoneisgood'); if(in_array($entered_name, $bannedNameParts)) { die('Username part is banned! Shit bro!'); }
I tried this however when I add more than 2 swearwords my site won't load. Anyone got a suggestion?
final public function validName($username) {
if(strlen($username) <= 25 && ctype_alnum($username))
{
if (strpos($username, "fuck") === FALSE) {
if (strpos($username, "cunt") === FALSE) {
return true;
}
}
else
{
return false;
}
}
You're missing a bracket and checking each word like that is poor, if you turn on PHP error displaying it'll show you the error and not just go white.
Jonteh's suggestion of an array is easily expandable, try:
Code:function checkName($username) { if(strlen($username) <= 25 && ctype_alnum($username)) { $bannedNames = array('fuck', 'cunt'); if (in_array($username, $bannedNames)) { return true; } else { return false; } } }