php file_get_contents returning false ...

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

php file_get_contents returning false ...

Hi,

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 = 'https://www.appsoma.com/blog/rss'; print_r($this->feed);echo PHP_EOL; // die('getting feed url'); $feed = file_get_contents($this->feed); var_dump($feed);
Tue, 11/06/2018 - 05:53
marcelorp

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);
      curl_close($ch);
      return $data;
}

echo get_content('http://example.com');


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.
Credits: https://stackoverflow.com/questions/3488425/php-ini-file-get-contents-ex...