[PHP] Banned username

Newbie Spellweaver
Joined
Oct 20, 2007
Messages
21
Reaction score
0
EDIT:
A user can bypass it by putting other characters... For example:
If a user create an account named: "admin" It blocks it, but if someone create an account named: "33Admin22" it let him create the account. How can fix it?
____


I'm new in Php and i'm trying to put a filter when someone register on my website
I put this on top of the page
PHP:
$banword = array("admin","adm1n");
PHP:
elseif ($name == $banword){
    echo 'username not allowed';
    exit();
}
It doesn't work can some fix this problem?
 
Last edited:
um, you'd need to loop through that array, but I guess it would be much easier just to do this
PHP:
$notAllowed = "admin";
$notAllowed2 = "adm1n";

if($name == $notAllowed OR $name == $notAllowed2) {
    echo 'username not allowed';
    exit();
}
 
Obviously that wont work -- $name is never equal to the $banword array. Use in_array() to check if a item is contained within a array.

PHP:
if (in_array($name, $banword))
{
// username not allowed
}

What foxx posted could work as well, though this may be easier, dunno.
 
Meth0d said:
Obviously that wont work -- $name is never equal to the $banword array. Use in_array() to check if a item is contained within a array.

PHP:
if (in_array($name, $banword))
{
// username not allowed
}

Definitely; efficient too!

...Or you could just create the admin and adm1n accounts yourself before anyone else does :)

OneMoreJosh suggesting the bargain technique. :P
 
Obviously that wont work -- $name is never equal to the $banword array. Use in_array() to check if a item is contained within a array.

PHP:
if (in_array($name, $banword))
{
// username not allowed
}
What foxx posted could work as well, though this may be easier, dunno.

It works ! Thanks.

EDIT:
A user can bypass it by putting other characters... For example:
If a user create an account named: "admin" It blocks it, but if someone create an account named: "33Admin22" it let him create the account. How can fix it?
 
It would be something like this:
PHP:
$name = strtolower($name);
foreach ($banword as $word){
	if (strpos($name, $word) === false){
		echo 'username not allowed';
		exit();
	}
}
 
Back