1

I want get the array of the curl handler but I tried with everything and nothing seems to work, this is the request:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $licenseServer);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $key_info);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$result = curl_exec($ch);
var_dump("<pre>".$result."</pre>");
var_dump("<pre>".curl_getinfo($ch, CURLINFO_HTTP_CODE)."</pre>");
curl_close($ch);

$result = json_decode($result, true);
switch (json_last_error()) {
echo....
}

if($result['valid'] == "true"){ 
             //license is valid.
            return true;
}
else {
return false;
}

var_dump show the handler as string instead of json obj, and get HTTP code 200, all seems well in the request, this is var_dump from response:

string(484) "
array(4) {
  ["key"]=>
  string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
  ["domain"]=>
  string(9) "localhost"
  ["validip"]=>
  string(3) "::1"
  ["product"]=>
  string(14) "GrowLiker_Lite"
}
string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
int(1)
string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
bool(true)
string(34) "licensed-jArUjtD3SSUC8hdVUy74i6vTZ"
{"valid":"true","info":{"id":"1","domain":"NA","expire":"NA","status":"1","product":"GrowLiker_Lite","validip":"NA"}}

But json_decode seems not work, this return null- JSON_ERROR_SYNTAX - Syntax error, malformed JSON. How can i parse and get the handler in array like this: $result['valid']

0 Answers0