Jump to content


Photo

need help with a function of mine


  • Please log in to reply
2 replies to this topic

#1 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 05 June 2006 - 09:25 PM

hello,

i made a function for my membership form to block certain usernames from being used but for some reason when i add more than 1 value in there, it seems to automatically kill the registration process stating the name used is banned when it isnt.

below is the code im using,

function blacklisted_usernames(){

global $username, $txt;

$sql = "SELECT * FROM ebb_blacklist";
$errorq = $sql;
$blacklist_q = mysql_query($sql) or die(error($error, "mysql", $errorq));
$numchk_user = mysql_num_rows($blacklist_q);
if($numchk_user == 0){
//bypass this check, nothing is found to check.
}else{
while ($row = mysql_fetch_assoc ($blacklist_q)){

if($numchk_user == 1){
$banlist_user = "/$row[blacklisted_username]/";
}else{
$banlist_user = "/";
$banlist_user .= "$row[blacklisted_username]|";
$banlist_user .="/";
}
if($row['match_type'] == "Wildcard"){
if (preg_match($banlist_user, $username)){
$error = $txt['usernameblacklisted'];
echo error($error, "general");
}
}else{
if ($username == $row['blacklisted_username']){
$error = $txt['usernameblacklisted'];
echo error($error, "general");
}
}
}
}
}

thanks.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 02:46 AM

The pattern syntax is probably incorrect.

And also there are flaws with it. For example, if "admin" is banned, "cadminz" would be blocked. Finally, I won't recommend something like this since it's a waste of resources. I would use:

$sql = "SELECT * FROM ebb_blacklist WHERE blacklisted_username='$username' LIMIT 1";
$blacklist_q = mysql_query($sql) or die(error($error, "mysql", $errorq));
if (mysql_num_rows($blacklist_q) === 1) {
   $error = $txt['usernameblacklisted'];
   echo error($error, "general");
}

This is a quite simple check. You can use MySQL's LIKE if you want partial matches as well.
~ D Kuang

#3 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 07 June 2006 - 04:11 PM

well i want to have wildcard matches so that if someone tries to do:

site_admin would get blocked.

but ok I'll try your way on this.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users