0

I am trying to fetch the data from the JSON, working as expected in localhost but it's not working in server. Even I tried with the JSON placeholder API.

PHP file

<?php $url = 'https://jsonplaceholder.typicode.com/posts';
$jsondata = file_get_contents($url); 
$obj = json_decode($jsondata, true);
var_dump($obj);
echo $obj[1]->title;
?>

I tried remove the true and tried with $obj = json_decode($jsondata); Still it returns null.

The same code working fine in my localhost.

Shadow
  • 33,525
  • 10
  • 51
  • 64
user2468312
  • 361
  • 2
  • 7
  • 21
  • Https and file_get_contents doesnt play well under some circumstances. Try wrapping that request with curl. – Teson Jul 13 '20 at 21:31
  • 3
    There may be a firewall at the hosting site that blocks it. Or PHP may have `fopen_url` disabled. – Barmar Jul 13 '20 at 21:31
  • Does this answer your question? [file\_get\_contents() error](https://stackoverflow.com/questions/6551379/file-get-contents-error) – Don't Panic Jul 13 '20 at 23:57
  • i have enable the fopen_url = On Now its working as expected. Thank you @Barmar – user2468312 Jul 14 '20 at 13:31

0 Answers0