phpmillion;1517797 wrote:In my personal opinion, it's not really important how often code will be executed. Even if OP executes it once a year, it's a good practice (and just a common sense) to keep the code as small and efficient as possible. And executing the same operation twice simply doesn't look logical.
I agree with you. Executing the code twice is resource consuming.
But, I'm curious:
Q1. Where in this code the code is forced to execute or loop twice ?
<?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);
//RESULT: Code working!
// 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 ? I mean, may I see a code sample ?
Q3. If I change this:
// 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');
to this:
// 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 (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 ?
@all members:
You're welcome to add a few lines of code onto Mini Proxy so that the proxy users are blocked from viewing pages that contain banned words.
https://github.com/joshdick/miniProxy/blob/master/miniProxy.php
Then, kindly attach the script here so that I can get hold of your update and install it on my site. You're welcome to ue 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.
