Some time we may face the error file_get_contents() failed to open stream: while we move site to other domain or fetching the third party websites data into to our data. Here are one solution for this error.

Here we will use cURL over file_get_contents()

function codecanal_curl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$feed = 'http://................'; /* Insert URL here */
$data = codecanal_curl($feed);

 

For Data from the SSL Websites :

function codecanal_curl($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$feed = 'https://................'; /* Insert URL here */
$data = codecanal_curl($feed);
There are currently no comments.