Error with file_get_contents and https

0

I have this code:

<?php
@$html = file_get_contents($urlFlujo);

echo $urlFlujo;
var_dump($html);

$lectorHtml = new DOMDocument();
@$lectorHtml->loadHTML($html);
?>

The problem is that when it comes to a url shortened with ow.ly for example, which then redirects to a web with https , the function file_get_contents returns false .

Is there a solution to this error?

    
asked by 26.06.2017 в 10:49
source

1 answer

1

By default file_get_contents does not redirect. You have to add a context and indicate it in the.

$context = stream_context_create(
    array (
        'http' => array (
            'follow_location' => true// follow redirects
        )
    )
);
$html = file_get_contents('http://www.site.net/', false, $context);

Based on this question

Links to the official PHP documentation for:

answered by 26.06.2017 в 10:58