PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Oct 21, 2017 7:57 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Oct 04, 2017 7:23 pm 
Online
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 171
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!


Top
 Profile  
 
PostPosted: Thu Oct 05, 2017 4:58 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6390
Location: Montreal, Canada
What have you tried so far? Where have you encountered issues? Have you looked at https://github.com/web-mech/badwords ?

You're obviously going to have to learn JS before being able to implement this, but you'll need to learn that anyhow. Do you know JS at all?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Thu Oct 05, 2017 5:57 am 
Online
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 171
You see, I want to run a public web proxy but I do not want my users viewing sites containing banned words. If I have 1k banned word and a page contains 1k words then my current php filter has to loop 1k*1k=1m times on a single page to check for banned words. Now, imagine the cpu usage. My host likely to object. On top of that, when thousands of users simultaneously use my web proxy then you can imagine how slow my service would become to load pages.
That is why at Stack Over Flow the php guru who is helping me build the php filter, suggests I look into the JS filter instead.

I have now been told that, many people surf with java and javascript disabled. Nothing would run with these surfers (web proxies). Plus, anytime I do something client side, it can be faked. In other words they could remove all banned words on the fly before my javascript ran. So a page with a banned word would appear to you as fine!
This is shocking news for me indeed! Client-side can be faked ? How ? You JS experts care to elaborate more ? I have to learn this loophole to prevent maliciousness in the future.
So, what is the solution then ? I mean, the php filter would be too slow and the page would load slowly and my users would get fedup and ditch the free service. What would you do if you were in my position ?

I do not know JS atall. I'm struggling with php. Can't take 2 giants all at once. If I can find a ready made script online then using my common sense I maybe able to customise it according to my needs asking a little here and there on many forums and reading a little tutorials (but I do not have the time, nor the patience to learn the full language) then I'll share the final version on all forums. Thus, I contribute back to the forums that helped me a little.
I'll google and see if I can find any free samples. I might find a few on Stack Over Flow.

You know my php project is nearly finished. I added a link click logger onto a free web proxy to log what users are browsing (with their permission). I wanted to add a words filter (banned words) so users don't view forbidden sites nor my proxy logs them. However, the php forums failed to advise me that the filtering is best done at the client side rather than server side. Else, the service will become slow. I learnt this at Stack Over Flow. Even though my php words filter is finished. I reckon the JS word filter would be best for my project.

The owner of this fiddle just brought it to my attention that she has written a fiddle and to check it out:
http://jsfiddle.net/rMJxR/33/

Or, I can use the jQuery library she says:
https://github.com/ChaseFlorell/jQuery.ProfanityFilter

Frankly, I do not know what a fiddle is. Checking it out now.
Neither I have a single bit of experience with jQuery lib.

I hope it does the job. You experts are welcome to check and give your opinions as feed-back to me and all the future newbies finding their way here. :)


Last edited by UniqueIdeaMan on Thu Oct 05, 2017 6:51 am, edited 2 times in total.

Top
 Profile  
 
PostPosted: Thu Oct 05, 2017 6:15 am 
Online
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 171
Anyone know any solution ?


Top
 Profile  
 
PostPosted: Thu Oct 05, 2017 5:02 pm 
Online
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 171
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.

Syntax: [ Download ] [ Hide ]
<?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", "smurf");
  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);
?>
 


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group