Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How To Check For Banned Word On Page With Javascript ?

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 843
    Answer it

    Folks,

    I'm trying to add a content filter (banned words filter) onto a web proxy. When the Javascript detects any of the banned words on the page, it should:

    * echo/print on screen/display a warning to the user:
    "Banned word "blah blah" found on page. You will be redirected to Google".

    * Then, redirect to Google.

    What would the code be to do all that ?
    I'd like to code see samples.
    I'm trying to build one in php but the php gurus say it is best the banned words checking is done on client-side. Else, the page would take too long to load (high cpu usage) if the checking is done on server side. I have no experience in writing Javascript code.

    Thank You!

 2 Answer(s)

  • Folks!

    Why do you reckon this code does not work ? I only see a blank page.
    The code will need to run everytime cURL loads a page so that the JS can check the page for banned words.

    [code]
    <?php
    /*
    ERROR HANDLING
    */

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_URL, 'https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X');
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );

    $result = curl_exec($curl);
    if (curl_errno($curl)) {
        echo 'Error:' . curl_error($curl);
    }
    $response = curl_getinfo( $curl );
    if($response['http_code'] == '200' )
    {
    ?>
    <script>
    $(function(){
            var pageData = "hello <a>example can have tags! swear word is </a><div> one..</div>";
       if(checkSwear(pageData)== false){
       //redirect to google
       }
    });

    function checkSwear(sentance) {
        
        var swear_words_arr=new Array("blow", "nut", "asshole");
      var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );
      if(regex.test(sentance)) {
        alert("Please refrain from using offensive words"); /* + alert_text */
        return false;
      } else {
      //alert(1)
          return true;
      }
    }
    </script>
    <?php
    }
    curl_close($curl);
    ?>
    [/code]
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: