darkcarnival Posted June 5, 2006 Share Posted June 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11271-need-help-with-a-function-of-mine/ Share on other sites More sharing options...
poirot Posted June 6, 2006 Share Posted June 6, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11271-need-help-with-a-function-of-mine/#findComment-42271 Share on other sites More sharing options...
darkcarnival Posted June 7, 2006 Author Share Posted June 7, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11271-need-help-with-a-function-of-mine/#findComment-42848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.