var_dump of a JSON response returns NULL

0 votes

I'm writing a script to accept Bitcoin payments. My $json variable returns null. var_dump() returns NULL.

I am using the following code:

 $receiving_address = BITCOIN_ADDRESS;
    if(get_magic_quotes_gpc()){
        $callback_url = urlencode(stripslashes(CALLBACK_URL));
    }  else {
        $callback_url = urlencode(CALLBACK_URL);
    }

    $ch = curl_init("https://blockchain.info/api/receive?method=create&address=$receiving_address&shared=false&callback=$callback_url");
    curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $json=json_decode(curl_exec($ch),true);

    var_dump($json);
    echo $json[0]->text;
Aug 28, 2018 in Blockchain by slayer
• 29,170 points
457 views

1 answer to this question.

0 votes

You should be aware of the chances that some code might not execute properly. Try the following code:

$response = curl_exec($ch);
if ($result === FALSE) {
   die("Curl failed with error: " . curl_error($ch));
}
$json = json_decode($response, true);
if (is_null($json)) {
   die("Json decoding failed with error: ". json_last_error());
}
answered Aug 28, 2018 by digger
• 26,550 points

Related Questions In Blockchain

0 votes
1 answer

how loop through a JSON Array of bitcoin transaction data

for($i=0; $i<count($result['out']); $i++) { echo ...READ MORE

answered Sep 21, 2018 in Blockchain by slayer
• 29,170 points
46 views
+1 vote
1 answer

I would like to create a blockchain network which will stay at the same level of complexity, is it possible?

You can very easily create a cryptocurrency having a ...READ MORE

answered Apr 4, 2018 in Blockchain by Christine
• 15,790 points
61 views
0 votes
1 answer

Can a hacker change data of a smart sontract without call contract function?

A contract's content cannot be changed internally. ...READ MORE

answered Apr 7, 2018 in Blockchain by Shashank
• 10,350 points
34 views
0 votes
1 answer
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,550 points
288 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
172 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,550 points
4,424 views
0 votes
1 answer

How to transact custom token instead of ethers using JSON rpc?

First create your custom token. Then develop ...READ MORE

answered Jul 10, 2018 in Blockchain by digger
• 26,550 points
44 views