0

Ok, So i am creating a simple callback function to check to see if the user has inserted a banned word. Here i what i have so far: (This is using codeigniter and tankauth)

$this->form_validation->set_rules('firstname', 'First Name', 'trim|alpha|xss_clean|min_length[2]|max_length[50]|callback_is_banned_word');
$this->form_validation->set_rules('lastname', 'Last Name', 'trim|alpha|xss_clean|min_length[2]|max_length[50]|callback_is_banned_word');

is_banned_word() function:

//Check if first or last name is a banned word
function is_banned_word($input) {
    $banned_words = array("word1","word2",...."wordn"); //This is a really long array
    foreach($banned_words as $words) {
        if (stripos($input,$words) !== false) {
            $this->form_validation->set_message('is_banned_word', 'There is a banned word your phrase.');
            return FALSE;
        }
        else {
            return TRUE;
        }
    }
    return TRUE;
}

Any help?

j08691
  • 204,283
  • 31
  • 260
  • 272
ageoff
  • 2,798
  • 2
  • 24
  • 39
  • why would theses words be banned? –  Sep 15 '12 at 02:47
  • They are curse words, offensive words, stuff like that. People cannot set a username or firstname lastname to these words. – ageoff Sep 15 '12 at 02:49
  • that never ever works, there are many many ways around it: "b a d w o r d" "b*a*d*W*o*r*d" "b ad w ord" etc etc etc and if you use a partial match that just dumb as some names have "bad" words in them –  Sep 15 '12 at 02:54
  • I have catches for that also. firstname lastname are alpha only. username cannot have spaces. and again, its a REALLY long list. – ageoff Sep 15 '12 at 02:57
  • that's even words spaces and non alpa are legitimate in names. –  Sep 15 '12 at 02:58
  • [Falsehoods Programmers Believe About Names](http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/) –  Sep 15 '12 at 03:00
  • Still, I think preventing someone from walking around with the f-bomb or n-word as a username is a nono and should be caught. If they want to get tricky and try to do it, then so be it. – ageoff Sep 15 '12 at 03:02
  • well the point is you want actully achieve that, you will block legitimate names and annoy people - oh well your call. –  Sep 15 '12 at 03:07

1 Answers1

0

whats is your question ?

function is_banned_word($input) {
    $banned_words = array("word1","word2",...."wordn"); //This is a really long array
        if (in_array( $input , $banned_words )) {
            $this->form_validation->set_message('is_banned_word', 'There is a banned word your phrase.');
            return FALSE;
        }
    return TRUE;
}
max
  • 3,614
  • 9
  • 59
  • 107
  • Something in this function breaks the site. If i comment out this function then the site works fine. If i uncomment it then the site breaks. There is something wrong that i cannot find. – ageoff Sep 15 '12 at 02:55
  • That's the problem. I dont. The site just no longer shows at all. If I could find where the php errors show then that would be awesome. Most of my experience so far is it works fine, or nothing shows up. – ageoff Sep 15 '12 at 02:58
  • the reason that sometimes it works ok and sometimes it just dies is becuz `is_banned_word` function returns true or false based on the word and the way that you handle it's result is the key here . first findout which one is cuzing the problem true of false and then just follow your code that handles that particular result . and also change your function with mine you don't need all that extra code – max Sep 15 '12 at 03:09
  • found my error. I had 'word,' instead of 'word', for one of the array values. FML. I am accepting this answer cause I am using your if statement anyway cause I dont want to change it back to what it used to be. – ageoff Sep 15 '12 at 03:11