简体   繁体   中英

JSON_decode with file_get_contents, why is not working?

I use the following simple code to calculate a copper price in my website.

<?php 

$copper_data = json_decode(file_get_contents('https://www.quandl.com/api/v3/datasets/LME/PR_CU.json?limit=1&api_key=XXXXXXX'), true);
$currency_data = json_decode(file_get_contents('https://openexchangerates.org/api/latest.json?app_id=XXXXXXX'), true);
$copper_lv_per_ton = $copper_data['dataset']['data'][0][2]*$currency_data['rates']['BGN'];

?>

The code works just fine in a static php page, but when included in Joomla article (via plugin called Sourcerer ) it does not work

The problem was that allow_url_fopen was disabled in php.ini or php73-fcgi.ini allow_url_fopen = 1 (or On)

In my server there are many files php73-fcgi.ini, php72-fcgi.ini and more... In all of them I found this allow_url_fopen and enabled it (set to 1 or On) then it worked.

Be careful because the change took 10-15 minutes in my case. I believe because of caching ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM