Jump to content

Archived

This topic is now archived and is closed to further replies.

darkcarnival

[resolved] username blacklist error

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.

Share this post


Link to post
Share on other sites
[code]$q = mysql_query("SELECT * FROM ebb_blacklist WHERE blacklisted_username LIKE '%$value%'") or die(mysql_error());[/code]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
i mean it doesnt work

enter in admin as an option it works but looking for siteadmin it doesnt.

i want to find any occurance of admin and ban it. though it looks like an impossible feat so far.

Share this post


Link to post
Share on other sites
Just to clarify... How are you calling this function? Example...

[code=php:0]
$name = 'siteadmin';
if (blacklisted_usernames($name)) {
  echo "sorry, that $name is a banned username";
}
[/code]

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Well the code should work fine. I notice in your last posted code you have neglected to add the % symbols around the variable $value within your query. They are required.

Share this post


Link to post
Share on other sites
i tried that and that doesnt work either.

i might have to quit on making a wildcard check, until i can have more time(i want to get this thing going soon)

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.