darkcarnival Posted August 23, 2006 Share Posted August 23, 2006 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:[code]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);}[/code]I've tried several other things but nothing has worked, any input is welcomed. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 23, 2006 Share Posted August 23, 2006 [code]$q = mysql_query("SELECT * FROM ebb_blacklist WHERE blacklisted_username LIKE '%$value%'") or die(mysql_error());[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted August 23, 2006 Share Posted August 23, 2006 hitman6003's suggestion would be much more efficient then using a loop for no reason.[code=php:0]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);}[/code] Quote Link to comment Share on other sites More sharing options...
darkcarnival Posted August 23, 2006 Author Share Posted August 23, 2006 that doesnt work, i already tried that. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 23, 2006 Share Posted August 23, 2006 What about it doesn't work? Quote Link to comment Share on other sites More sharing options...
darkcarnival Posted August 23, 2006 Author Share Posted August 23, 2006 i mean it doesnt workenter 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. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 23, 2006 Share Posted August 23, 2006 You will have to break the word appart to search for it's peices. Quote Link to comment Share on other sites More sharing options...
trq Posted August 23, 2006 Share Posted August 23, 2006 Just to clarify... How are you calling this function? Example...[code=php:0]$name = 'siteadmin';if (blacklisted_usernames($name)) { echo "sorry, that $name is a banned username";}[/code] Quote Link to comment Share on other sites More sharing options...
darkcarnival Posted August 23, 2006 Author Share Posted August 23, 2006 here is the full code im using:[code]#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";}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted August 23, 2006 Share Posted August 23, 2006 Your code will fail if your query finds more than one record containing the word admin.Does this work?[code=php:0]<?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"; }?>[/code] Quote Link to comment Share on other sites More sharing options...
darkcarnival Posted August 23, 2006 Author Share Posted August 23, 2006 no, i tried that too. Quote Link to comment Share on other sites More sharing options...
trq Posted August 23, 2006 Share Posted August 23, 2006 Can I see the output of?[code=php:0]$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 />"; }}[/code] Quote Link to comment Share on other sites More sharing options...
darkcarnival Posted August 23, 2006 Author Share Posted August 23, 2006 i only added one entry which is admin Quote Link to comment Share on other sites More sharing options...
trq Posted August 23, 2006 Share Posted August 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
darkcarnival Posted August 23, 2006 Author Share Posted August 23, 2006 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) Quote Link to comment Share on other sites More sharing options...
trq Posted August 23, 2006 Share Posted August 23, 2006 Sorry... I dont know what I was thinking. You'd need to check the other way around. This might be the easiest solution.[code=php:0]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; } }[/code] Quote Link to comment Share on other sites More sharing options...
darkcarnival Posted August 23, 2006 Author Share Posted August 23, 2006 well ok, now it works :Dthorpe, I have to give you a major thank you for helping me with this :) Quote Link to comment 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.