PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Dec 15, 2017 6:40 pm

All times are UTC - 5 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Banned Words Filter
PostPosted: Thu Oct 19, 2017 5:25 am 
Offline
Forum Contributor

Joined: Wed Jan 18, 2017 4:43 pm
Posts: 179
Folks,

Q1. Do you consider the following code to be safe & sound to substitute banned words found on the page ?
If not, then maybe I try str_replace instead of preg_match ?

Code:
<?php

/*
ERROR HANDLING
*/
//declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

// 1). Set banned words.
$banned_words = array("blow", "nut", "bull****");
// 2). $curl is going to be data type curl resource.
$curl = curl_init();
// 3). Set cURL options.
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 );
// 4). Run cURL (execute http request).
$result = curl_exec($curl);
if (curl_errno($curl)) {
    echo 'Error:' . curl_error($curl);
}
$response = curl_getinfo( $curl );
if($response['http_code'] == '200' )
{
    $regex = '/\b';     
    $regex .= implode('\b|\b', $banned_words);   
    $regex .= '\b/i';
    $substitute = '****';
    $cleanresult = preg_replace($regex, $substitute, $result);
    echo $cleanresult;
}
curl_close($curl);
?>


Q2. How would you code it yourself ? I mean, may I see a code sample ? I've done my best.

Q3. If I change this:

Syntax: [ Download ] [ Hide ]
// 3&#41;. Set cURL options.
curl_setopt&#40;$curl, CURLOPT_URL, &#39;https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X&#39;&#41;;


to this:

Code:
// 3). Set cURL options.
$url = "https://www.buzzfeed.com/mjs538/the-68-words-you-cant-say-on-tv?utm_term=.xlN0R1Go89#.pbdl8dYm3X";
curl_setopt($curl, CURLOPT_URL, "$url");


then it works fine. But, is it safe to do it like this ?

Q4. Where on Mini Proxy, on which line, would I add the banned words filter code (the code which you see in my Q1) or your banned words filter code so that, when banned words are found on the proxied pages, then the banned words are substituted ?

Folks, you're welcome to add a few lines of code onto the Mini Proxy so that the proxy users are blocked from viewing pages that contain banned words.
Mini Proxy is here:
https://github.com/joshdick/miniProxy/b ... iProxy.php

Finally, kindly attach the script here so that I can get hold of your update and install it on my site. You're welcome to use the proxy regular and you'e welcome to invite others to use it to.
I've googled but no luck in finding a shared webhost who will allow me to run a web proxy. :banghead:
Therefore, you're welcome to recommend many. :wink:
I'll only hire the dedicated server once I've picked-up a lot of regular users. :D


Top
 Profile  
 
 Post subject: Re: Banned Words Filter
PostPosted: Thu Oct 19, 2017 5:44 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6404
Location: Montreal, Canada
Enough with the duplicate threads.

viewtopic.php?f=1&t=144493

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 12 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