Jump to content

[resolved] username blacklist error


darkcarnival

Recommended Posts

im back again,

with 1 problem left to go im stuck on a solution for my username blacklist checker.

it can find an exact item like admin or webmaster but if wanted to look for:

siteadmin it will not block that.

i want to be able to block any occurance of admin.

I've troied several things but none seem to do it. her is the code im using:

[code]function blacklisted_usernames($value){

$q = mysql_query("SELECT * FROM ebb_blacklist") or die(mysql_error());
while ($row = mysql_fetch_assoc($q)){

if (strstr($row['blacklisted_username'], $value) !== false){
$blklist = 1;
}else{
$blklist = 0;
}
}
return ($blklist);
}[/code]

I've tried several other things but nothing has worked, any input is welcomed.
Link to comment
Share on other sites

hitman6003's suggestion would be much more efficient then using a loop for no reason.

[code=php:0]
function blacklisted_usernames($value) {
  $q = mysql_query("SELECT blacklisted_username FROM ebb_blacklist WHERE blacklisted_username LIKE '%$value%'") or die(mysql_error());
  return mysql_num_rows($q);
}
[/code]
Link to comment
Share on other sites

here is the full code im using:

[code]#db connection stuff.
$username = "siteadmin";
function blacklisted_usernames($value){


$q = mysql_query("SELECT * FROM ebb_blacklist where blacklisted_username like '$value'") or die(mysql_error());
$n = mysql_num_rows($q);

if($n == 1){
$blklist = 1;
}else{
$blklist = 0;
}
return ($blklist);
}
#check it
$blklist = blacklisted_usernames($username);
if ($blklist == 1) {
echo "username ban!!";
}elseif($blklist == 0){
echo "Your good to go, username pass test.";
}else{
echo "blank.$blklist";
}
?>[/code]
Link to comment
Share on other sites

Your code will fail if your query finds more than one record containing the word admin.

Does this work?

[code=php:0]
<?php

  function blacklisted_usernames($value) {
      $q = mysql_query("SELECT blacklisted_username FROM ebb_blacklist WHERE blacklisted_username LIKE '%$value%'") or die(mysql_error());
      return mysql_num_rows($q);
  }
  $name = 'siteadmin';
  if (blacklisted_usernames($name)) {
      echo "sorry, that $name is a banned username";
  }

?>
[/code]
Link to comment
Share on other sites

Can I see the output of?

[code=php:0]
$q = mysql_query("SELECT blacklisted_username FROM ebb_blacklist") or die(mysql_error());
if ($q) {
  while ($r = mysql_fetch_assoc($q)) {
    echo $r['blacklisted_username']."<br />";
  }
}
[/code]
Link to comment
Share on other sites

Sorry... I dont know what I was thinking. You'd need to check the other way around. This might be the easiest solution.

[code=php:0]
function blacklisted_usernames($value) {
  $result = mysql_query("SELECT blacklisted_username FROM ebb_blacklist") or die(mysql_error());
  if ($result) {
    while($row = mysql_fetch_assoc($result)) {
      if (strstr($value,$row['blacklisted_username'])) {
        return true;
      }
    }
    return false;     
  }     
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.