-3

I want to echo the word 'Active' from the json.

"status":"Active"

PHP/CURL:

$ch = curl_init("http://ip:port/player_api.php?username=$username&password=$password");
    $headers = array();
    $headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0";

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    $result = curl_exec($ch);
// Now i need to decode the json

Json:

{"user_info":{"username":"test","password":"test","message":"","auth":1,"status":"Active","exp_date":null,"is_trial":"0","active_cons":"0","created_at":"000","max_connections":"1","allowed_output_formats":["m3u8","ts","rtmp"]},"server_info":{"url":"111.111.111","port":"80","rtmp_port":"80","timezone":"test","time_now":"2018-03-20"}}
vedder
  • 1
  • @ObsidianAge No, i know how to decode with php. but i need to know how to decode with curl – vedder Mar 19 '18 at 23:25
  • 3
    You have the JSON stored as the PHP variable `$result`; you need to decode it with PHP. Why do you think you need to decode it with CURL itself? CURL has no knowledge of the structure of data returned. You most definitely need to decode your JSON with PHP, and that link tells you exactly how to do so. – Obsidian Age Mar 19 '18 at 23:26

1 Answers1

0

As Obsidian Age already said, you cannot use CURL to decode JSON. You can use PHP though:

You can use CURL to get the JSON file (I think you already have that):

$url = 'http://ip:port/player_api.php?username=$username&password=$password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$json = curl_exec($ch);
curl_close($ch);

Then you can use PHP to decode the JSON get the status = active.

$data = json_decode($json, true);

echo $data['user_info']['status'];
Edward
  • 2,291
  • 2
  • 19
  • 33