Jump to content


Photo

[resolved] username blacklist error


  • Please log in to reply
16 replies to this topic

#1 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 01:26 AM

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:

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);
}

I've tried several other things but nothing has worked, any input is welcomed.

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 23 August 2006 - 01:33 AM

$q = mysql_query("SELECT * FROM ebb_blacklist WHERE blacklisted_username LIKE '%$value%'") or die(mysql_error());


#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 01:37 AM

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

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);
}


#4 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 01:48 AM

that doesnt work, i already tried that.

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 23 August 2006 - 01:49 AM

What about it doesn't work?

#6 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 02:03 AM

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.

#7 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 23 August 2006 - 02:05 AM

You will have to break the word appart to search for it's peices.

#8 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 02:08 AM

Just to clarify... How are you calling this function? Example...

$name = 'siteadmin';
if (blacklisted_usernames($name)) {
  echo "sorry, that $name is a banned username";
}


#9 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 02:35 AM

here is the full code im using:

#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";
}
?>


#10 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 02:53 AM

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

Does this work?

<?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";
  }

?>


#11 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 02:56 AM

no, i tried that too.

#12 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 03:02 AM

Can I see the output of?

$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 />";
  }
}


#13 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 03:14 AM

i only added one entry which is admin

#14 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 03:17 AM

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.

#15 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 03:22 AM

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)

#16 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 23 August 2006 - 03:37 AM

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

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;       
  }       
}


#17 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 23 August 2006 - 03:59 AM

well ok, now it works :D

thorpe, I have to give you a major thank you for helping me with this :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users