Post
Topic
Board Services
Re: fix my php - blockchain.info ticker call
by
PotatoPie
on 17/12/2014, 06:24:17 UTC
Quote from: lewellyn link=javascript:void(0);topic=896192.msg9863804#msg9863804 date=1418797017
the following code was working to retrieve the usd price, now for some reason its not

    require 'Mysql.php';
    require 'Util.php';
    $file = file_get_contents("http://blockchain.info/ticker");
    $vars = json_decode($file, true);
    $usd = $vars['USD']['15m'];
    $net_usd = number_format((($usd) * (100 - Settings::fee)) / 100, 2);

echo $net_usd returns zero when should be the price. offering 0.1 btc to someone who can fix.

You left out where Settings::fee is coming from. If the class Settings isn't found, you'd get a fatal error. The fact that you aren't indicates that it's mis-defined somewhere. You'll need to either post more code, or do digging with that lead yourself. Smiley

Probably in Util.php, but I doubt that would be an area of concern as it seems to have just 'stopped working'.

the following code was working to retrieve the usd price, now for some reason its not

    require 'Mysql.php';
    require 'Util.php';
    $file = file_get_contents("http://blockchain.info/ticker");
    $vars = json_decode($file, true);
    $usd = $vars['USD']['15m'];
    $net_usd = number_format((($usd) * (100 - Settings::fee)) / 100, 2);

echo $net_usd returns zero when should be the price. offering 0.1 btc to someone who can fix.

Try changing the url in file_get_contents to be https://

Code:
$file = file_get_contents("https://blockchain.info/ticker");

Blockchain.info recently changed some things around, and maybe you're not getting the file through redirect.

I was able to use http and it seems that there is no redirects without https. Blockchain is behind cloudflare which could be causing blocking issues (I've had it various times before).