473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How To Check For Banned Word On Page With Javascript ?

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:

* As soon as a banned word is detected, it should not check for any more but immediately echo/print on screen/display a warning to the user with the first banned word spotted:
"Banned word "blah" found on page. You will be redirected to Google".
* Then, redirect to Google.
* Dump to database the banned word found, and the url of the page the banned word was found on. Eg.

Banned Word Found|Url|Date & Time of the Server
--------------------------------------------------------
ass|donkey-ass.com|25-01-2007, 03:00:00



The only requirement is that, I should be able to feed a list of banned words it should check for.

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!
Oct 5 '17 #1
2 2277
Niheel
2,460 Expert Mod 2GB
For live checking of words as they're being typed yes javascript might be the best approach.

You should use a library like jquery to consume the input and run it through a filter and set the alert when it's found.

Take a look at the following github rep
https://github.com/ChaseFlorell/jQuery.ProfanityFilter
Oct 5 '17 #2
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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /*
  3. ERROR HANDLING
  4. */
  5. // 1). Set banned words.
  6. $banned_words = array("Prick","Dick", "blow", "cock");
  7. // 2). $curl is going to be data type curl resource.
  8. $curl = curl_init();
  9. // 3). Set cURL options.
  10. curl_setopt($curl, CURLOPT_URL, 'https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X');
  11. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  12. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true );
  13. // 4). Run cURL (execute http request).
  14. $result = curl_exec($curl);
  15. if (curl_errno($curl)) {
  16.     echo 'Error:' . curl_error($curl);
  17. }
  18. $response = curl_getinfo( $curl );
  19. if($response['http_code'] == '200' )
  20. {
  21. ?>
  22. <script>
  23. $(function(){
  24.         var pageData = "hello <a>example can have tags! swear word is </a><div> one..</div>";
  25.    if(checkSwear(pageData)== false){
  26.    //redirect to google
  27.    }
  28. });
  29.  
  30. function checkSwear(sentance) {
  31.  
  32.     var swear_words_arr=new Array("blow", "nut", "asshole");
  33.   var regex = new RegExp('\\b(' + swear_words_arr.join('|') + ')\\b', 'i' );
  34.   if(regex.test(sentance)) {
  35.     alert("Please refrain from using offensive words"); /* + alert_text */
  36.     return false;
  37.   } else {
  38.   //alert(1)
  39.       return true;
  40.   }
  41. }
  42. </script>
  43. <?php
  44. }
  45. curl_close($curl);
  46. ?>
  47.  
  48.  
Oct 5 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Anastasios Hatzis | last post by:
Hi I have set up a page for a project on SourceForge. This project is about a bundled tech platform, which contains Python (among other OSS tools), so I also included a page with regard to...
0
by: Andy | last post by:
The question is in the title really. How can I programatically check from VB.net whether a word document contains macros? We basically want to reduce the chance of storing / dealing with any word...
2
by: stephen | last post by:
Hi, I am binding the button.text dynamicall depending on the selection value of the dropdownlist, at the same time I am trying to use a javascript to alert users, but it does not fire. This is...
2
by: AmitKu | last post by:
<script> function CheckChange() { var mycheck = document.getElementById('test'); mycheck.check = true; } </script> <body> <form id="form1" runat="server">
9
by: popamit60 | last post by:
Tell me Guys , If there is any Fun to check float numbers in javascript ?? Tell me d solution Thanks Amit
6
by: James Yang | last post by:
"bad page", especially in table, is a risk for database maintenance. The particular access attempt for corrupt blocks may not occur often, and corrupt DB2 blocks are not recognized during a...
12
by: foolsmart2005 | last post by:
There are 10 webpages on the host, e.g. 001.html, 002.html, 003,html, 004.html, ......010.html I want to check whether the page is the last page. How can I do. In the index.html -Go to last...
8
by: Alan | last post by:
Hello, I need to write a systemtray program to check every minute if a certain intranet page exists. Would "webBrowser.Navigate" and catching exceptions to it be a good choice in terms of load...
3
Frinavale
by: Frinavale | last post by:
Hi there! I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript. I have seen suggested solutions using an ActiveX control to check...
0
surusoni88
by: surusoni88 | last post by:
I got one project with some requirements. Basically my client provide data entry work. In that he converts image files(scan copy of articles, forms etc) to document file (MS word) by typing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.