Folks,
Why is cURL failing to fetch the page ? All this time it worked.
Echoes "Page fetching problem!"
Why is cURL failing to fetch the page ? All this time it worked.
Echoes "Page fetching problem!"
PHP:
<?php
//Required PHP Files.
include 'config.php';
include 'header.php';
//1). Set Banned Words.
$banned_words = array("asshole", "nut", "bullshit");
$url = "http://devshed.com";
// 2). $curl is going to be data type curl resource.
$curl = curl_init();
// 3). Set cURL options.
curl_setopt($curl, CURLOPT_URL, "$url");
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 page is fetched then replace banned words found on page.
if($response['http_code'] == '200' )
{
$regex = '/\b';
$regex .= implode('\b|\b', $banned_words);
$regex .= '\b/i';
$substitute = 'BANNED WORD REPLACED';
$clean_result = preg_replace($regex, $substitute, $result);
//Present the banned words filtered webpage.
echo $clean_result;
}
else
{
//Show error if page fetching failed.
echo "Page fetching problem!";
exit();
}
?>