Annie Khalid Annie Khalid - 7 months ago 47
PHP Question

How to access object in php

i am accessing object property with following code

$address = $_POST['address'];
$balance = file_get_contents(''. $address);
echo $balance->data->available_balance;

Actually i want to echo available_balance and output of print_r is this

"status" : "success",
"data" : {
"network" : "BTC",
"available_balance" : "0.00000000",
"pending_received_balance" : "0.00000000",
"balances" : [
"user_id" : null,
"label" : null,
"address" : "xxxxxxxxxxxxxxxxxxxxxxxxx",
"available_balance" : "0.00000000",
"pending_received_balance" : "0.00000000"

the next part of this question is please suggest me how to protect from SQl Injection Attack, in my project all forms are submitted through ajax, if user can sent only 20 requests to database in a day from one IP, is it will be good in SQL injection Protection.


I'm assuming this is a JSON data, so you've to decode it as PHP object first. Try the following code.

$balance = json_decode($balance);

echo $balance->data->balances[0]->available_balance