I added this filter code:
PHP Code:
Code: Select all
//SET THE BANNED WORDS.
$banned_words = array("prick","dick","<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>");
//SUBSTITUTE THE BANNED WORDS ON PROXIED PAGE (CONTENT FILTERING).
if($responseInfo['http_code'] == '200' )
{
$regex = '/\b'; // The beginning of the regex string syntax
$regex .= implode('\b|\b', $banned_words); // joins all the banned words to the string with correct regex syntax
$regex .= '\b/i'; // Adds ending to regex syntax. Final i makes it case insensitive
$substitute = '****';
$cleanresponse = preg_replace($regex, $substitute, $response);
echo $cleanresponse;
}
After this as you suggested:
$response = makeRequest($url);
$rawResponseHeaders = $response["headers"];
$responseBody = $response["body"];
But, I get error:
[text]Notice: Undefined variable: responseInfo in C:\xampp\htdocs\proxy\browser_experimenting.php on line 304[/text]
Never should have got that, as the variable is defined in line 169. (Maybe, it's within a condition. Hard to see as the original programmer made it messy).
And so, I lowered my filter code another line. Below these:
$response = makeRequest($url);
$rawResponseHeaders = $response["headers"];
$responseBody = $response["body"];
$responseInfo = $response["responseInfo"];
That way, my filter code is underneath the $responseInfo.
However, this time more errors:
[text]Warning: preg_replace(): Compilation failed: nothing to repeat at offset 21 in C:\xampp\htdocs\proxy\\browser_experimenting.php on line 311
Warning: preg_replace(): Compilation failed: nothing to repeat at offset 21 in C:\xampp\htdocs\proxy\\browser_experimenting.php on line 311
Notice: Array to string conversion in C:\xampp\htdocs\proxy\\browser_experimenting.php on line 311
Warning: preg_replace(): Compilation failed: nothing to repeat at offset 21 in C:\xampp\htdocs\proxy\\browser_experimenting.php on line 311
Notice: Array to string conversion in C:\xampp\htdocs\proxy\browser_experimenting.php on line 312
Array[/text]
I do not understand hy the preg_replace is failing this time when it did not before.
Anyway, earlier on, I placed my filter code on line 170 but no luck:
//Set the request URL.
curl_setopt($ch, CURLOPT_URL, $url);
//Make the request.
$response = curl_exec($ch);
$responseInfo = curl_getinfo($ch);
On many of my 3hrs experiments, I have been shifting the filter code on many lines and even changing the variable name but no luck.
Changing this:
Code: Select all
//SET THE BANNED WORDS.
$banned_words = array("prick","dick","<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>");
//SUBSTITUTE THE BANNED WORDS ON PROXIED PAGE (CONTENT FILTERING).
if($responseInfo['http_code'] == '200' )
{
$regex = '/\b'; // The beginning of the regex string syntax
$regex .= implode('\b|\b', $banned_words); // joins all the banned words to the string with correct regex syntax
$regex .= '\b/i'; // Adds ending to regex syntax. Final i makes it case insensitive
$substitute = '****';
$cleanresponse = preg_replace($regex, $substitute, $response);
echo $cleanresponse;
}
to this:
PHP Code:
Code: Select all
//SET THE BANNED WORDS.
$banned_words = array("Prick","****","***");
//SUBSTITUTE THE BANNED WORDS ON PROXIED PAGE (CONTENT FILTERING).
if($responseInfo['http_code'] == '200' )
{
$regex = '/\b'; // The beginning of the regex string syntax
$regex .= implode('\b|\b', $banned_words); // joins all the banned words to the string with correct regex syntax
$regex .= '\b/i'; // Adds ending to regex syntax. Final i makes it case insensitive
$substitute = '****';
$url = preg_replace($regex, $substitute, $response);
echo $url;
}
Sometimes, even removed the echoes when I saw the proxy showing duplicate of the page where when the top version was proxied with no content filtering and the bottom version unproxied with content filtering. And vice versa.
[text]echo $cleanresponse;[/text]
[text]echo $url;[/text]
I reckon the answer lies in the filter code. I'm not doing it right. Any example I can see from you on how the filter should be coded and put under which particular line ?
The original Mini Proxy code is here:
https://github.com/joshdick/miniProxy/b ... iProxy.php