Jump to content

need help with a function of mine


darkcarnival

Recommended Posts

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,

[code]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");
}
}
}
}
}[/code]

thanks.
Link to comment
https://forums.phpfreaks.com/topic/11271-need-help-with-a-function-of-mine/
Share on other sites

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:

[code]$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");
}[/code]

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

Archived

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

×
×
  • 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.