Jump to content

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