3

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

1
  • Your decoding in your vardump but not anywhere else? Put your decoded json into a variable then access it Commented Nov 26, 2016 at 12:53

1 Answer 1

3
$res_decoded = json_decode($result);
echo $res_decoded->token;
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, big help i have stumble into another problem ill try to solve this first then ask hel when i cant do it :D
hi i just have folluw-up question is it possible to echo it cleanly like having newline on every array or object its really hard to find the data its lump up together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.