Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php code trying to echo json data

Tags:

json

php

I have this output and i'am just trying to echo token or store token in a variable

object(stdClass)#1 (9) {
 ["loggedIn"]=> bool(true) 
["token"]=> string(32) "xe5b6bHPPo-_nAvB78NfTpopq9e44bYb" 
["secret"]=> string(20) "icCPoDvcf1Vvm2i7-6GM" 
["expirationTimestamp"]=> string(24) "2016-11-26T16:32:29.728Z" 
["type"]=> string(4) "USER" 
["data"]=> object(stdClass)#2 (17)}

here is my code:

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://security.voluum.com/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


$headers = array();
$headers[] = "Authorization: Basic plFubTHhcl93MzA4QHJJkQ9vqmNvwTpMNYYUIz5kcm9s";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

var_dump(json_decode($result));
var_dump(json_decode($result, true));

echo $result->token;
curl_close ($ch);

?>

is the code above correct? how can i extract a single data from the output? please help me

like image 381
Zyrd Jan Avatar asked Jul 05 '26 19:07

Zyrd Jan


1 Answers

$res_decoded = json_decode($result);
echo $res_decoded->token;
like image 144
AlexandrX Avatar answered Jul 07 '26 08:07

AlexandrX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!