php file_get_contents returning false ...

2 posts / 0 new
Last post
#1 Tue, 11/06/2018 - 01:31

php file_get_contents returning false ...


I am stuck with the issue.

Trying to retrieve rss from my url to a sub path, I am getting false. But the rss appears when retrieving it from the browser.

Here is my code. Could someone please advice me on what I should do ?

    $this->feed = '';

    print_r($this->feed);echo PHP_EOL;

    // die('getting feed url');

    $feed = file_get_contents($this->feed);

Tue, 11/06/2018 - 05:53

What is your php.ini configuration? In special the allow_url_fopen value.

Here is some code in PHP to get the content of an external URL, but using the CURL (recommended).

function get_content($URL){
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, $URL);
      $data = curl_exec($ch);
      return $data;

echo get_content('');

If you dont have curl installed on your server, here is some tips for CentOS:

yum install curl
yum install php-curl
yum install rh-php70-php-curl

The install of PHP depends on the version that you are using.

Topic locked