Jump to content


Photo

need help with my banning function


  • Please log in to reply
5 replies to this topic

#1 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 08 June 2006 - 04:47 PM

hey,

im trying to fix my banning function and currently its not workng like it should.

basically its suppose to ban users who have a certain email or username but when i test it out it lets the banned email through. here is the code im using:

function check_email(){

global $email, $txt, $db;

$sql = "SELECT * FROM ebb_banlist WHERE ban_type='Email'";
$errorq = $sql;
$banemail_q = mysql_query($sql) or die(error($error, "mysql", $errorq));
$numchk = mysql_num_rows($banemail_q);
if($numchk == 0){
//bypass this check, nothing is found to check.
}else{
while ($row = mysql_fetch_assoc ($banemail_q)){

if($row['match_type'] == "Wildcard"){
$db->run = "SELECT * FROM ebb_banlist WHERE ban_type='Email' and ban_item like '%$email%'";
$match_chk = $db->num_results();
$db->close();
#see if a match is found.
if ($match_chk == 1){
$error = $txt['emailban'];
echo error($error, "general");
}
}else{
$db->run = "SELECT * FROM ebb_banlist WHERE ban_type='Email' and ban_item='$email'";
$match_chk = $db->num_results();
$db->close();
#see if a match is found.
if ($match_chk == 1){
$error = $txt['emailban'];
echo error($error, "general");
}
}
}
}
}

I'm really stumped on this, and ive tried other ways with no success too. please help me.

thanks.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 June 2006 - 05:09 PM

umm.. i think you're making it more difficult than it really is. in essence, it is no different than checking a table to see if an entry already exists (like, a username in a register script)

$email = 'email@to.check';
$sql = "select * from bannedemails where email like '%$email%'";
$rs = mysql_query($sql);
$num = mysql_num_rows($rs);
if ($num > 0) {
  echo "this email is banned!";
} else {
  // do whatever, like continue to register
}




Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 poirot

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

Posted 08 June 2006 - 06:01 PM

darkcarnival, you are overcomplicating things. I've redone the function and actually set a database to test it.

Since I didn't knew what your error(), $txt, and so on, did, I made up them and also the database.

<?php

// This is MySQL connection stuff
mysql_connect('localhost', 'user', 'pass');
mysql_select_db('test');

// This is an error handling function I coded based on what I see
function error($error, $type, $details="")
{
   echo 'Error: ' . $error . '<br />';
   echo 'Type: ' . $type . '<br />';
   if (!empty($details)) {
      echo 'Deatils: ' . $details . '<br />';
   }
}

// Retrieves the email
$email = $_GET['email'];

// This is what I supposed your $txt to be.
$txt = array ('emailban' => 'Your Email is banned');

// This is a rewritten check_email() function
// It returns true if the email is not banned, false otherwise
// It works based on how I think your database is structured.
function check_email()
{
   global $email;

   $sql = "SELECT * FROM ebb_banlist WHERE ban_type='Email' AND ban_item LIKE '%$email%'";

   $banemail_q = mysql_query($sql) or die(error(mysql_error(), "mysql", $sql));

   if (mysql_num_rows($banemail_q) != 0) {

      while ($row = mysql_fetch_assoc($banemail_q)) {
         if ($row['match_type'] == "Wildcard") {
            $error = true;
         } else {
            if ($row['ban_item'] == $email) {
               $error = true;
            }
         }
      }
   }
   return ($error) ? false : true;
}

// This is basically how to use the function
if (!check_email()) {
   $error = $txt['emailban'];
   echo error($error, "general");
} else {
   echo 'You\'re good to go!';
}

?>

Here is an SQL dump of the test database:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]--
-- Table structure for table `ebb_banlist`
--

CREATE TABLE `ebb_banlist` (
`id` int(11) NOT NULL auto_increment,
`ban_type` varchar(32) NOT NULL default '',
`match_type` varchar(32) NOT NULL default '',
`ban_item` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;

--
-- Dumping data for table `ebb_banlist`
--

[span style=\'color:blue;font-weight:bold\']INSERT[/span] INTO `ebb_banlist` VALUES (1, 'Email', 'Wildcard', 'test@test.com.nc');
[span style=\'color:blue;font-weight:bold\']INSERT[/span] INTO `ebb_banlist` VALUES (2, 'Email', '', 'gargoyle@google.com'); [!--sql2--][/div][!--sql3--]

With this, I ran some test emails:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]test@test.com.cn -> wildcard on

test@test.com -> banned
test@test.com.cn -> banned

gargoyle@google.com -> wildcard off

gargoyle@google.com -> banned
gargoyle@google.com.nc -> not banned[/quote]
~ D Kuang

#4 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 08 June 2006 - 06:38 PM

ok ill give that a try.

btw $txt is a language variable(i have other since this program is multi-langual supported)

error() is a error printing function i made to make displaying errors easier and more detailed ;)

#5 poirot

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

Posted 08 June 2006 - 06:39 PM

[!--quoteo(post=381530:date=Jun 8 2006, 11:38 AM:name=darkcarnival)--][div class=\'quotetop\']QUOTE(darkcarnival @ Jun 8 2006, 11:38 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
ok ill give that a try.

btw $txt is a language variable(i have other since this program is multi-langual supported)

error() is a error printing function i made to make displaying errors easier and more detailed ;)
[/quote]
Indeed, I thought so and made simple replicas of them [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]
~ D Kuang

#6 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 08 June 2006 - 06:59 PM

EDIT:

ok after a small workaround i got it to work correctly. :)

thank you for your help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users