Banned Words Filter
Posted: Thu Oct 19, 2017 5:25 am
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 ?
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:
to this:
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.
Therefore, you're welcome to recommend many.
I'll only hire the dedicated server once I've picked-up a lot of regular users.
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: Select all
<?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);
?>Q3. If I change this:
Code: Select all
// 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');Code: Select all
// 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");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.
Therefore, you're welcome to recommend many.
I'll only hire the dedicated server once I've picked-up a lot of regular users.