When I put a URL in browser, I get the output (bellow)
{"categories":[{"id":"16","name":"Arm Locks"},{"id":"555","name":"Articles"},{"id":"19","name":"Back Control"},{"id":"21","name":"Brazilian Jiu Jitsu"},{"id":"12","name":"Chokes"},{"id":"15","name":"Crank"},{"id":"14","name":"Escapes"},{"id":"554","name":"Grappling Videos"},{"id":"10","name":"Guard and Rubber Guard"},{"id":"13","name":"Guard Breaks"},{"id":"23","name":"Half Guard"},{"id":"26","name":"Japanese Jujutsu"},{"id":"1","name":"Jiu Jitsu Training"},{"id":"5","name":"Jiu Jitsu Videos"},{"id":"25","name":"Leg Locks"},{"id":"27","name":"MMA"},{"id":"17","name":"Mount"},{"id":"30","name":"North South Position"},{"id":"556","name":"Platinum Members Only"},{"id":"29","name":"Self Defense"},{"id":"18","name":"Side Control"},{"id":"28","name":"Strikes"},{"id":"11","name":"Sweeps"},{"id":"20","name":"Theory & Discussions"},{"id":"9","name":"Throws"},{"id":"31","name":"Wrestling"},{"id":"22","name":"Wrist Locks"}]}
But when I try to parse using PHP (PHP Code and output)
PHP Code
<?php
$url = "https://domain.com/apis/cats.php?type=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json = curl_exec($ch);
$dcjsn = json_decode($json);
foreach ($dcjsn->categories as $cat){
echo $cat->id;
echo "<br>";
}
And output is:
555
15
14
554
13
23
26
25
27
17
30
29
18
28
20
9
22
Mean about 10 items missing!
I failed to identify the error in my code. I’ve tried with file_get_contents() also but no luck.
Addition:
result of var_dump($json)
string(574) "{"categories":[{"id":"555","name":"Articles"},{"id":"15","name":"Crank"},{"id":"14","name":"Escapes"},{"id":"554","name":"Grappling Videos"},{"id":"13","name":"Guard Breaks"},{"id":"23","name":"Half Guard"},{"id":"26","name":"Japanese Jujutsu"},{"id":"25","name":"Leg Locks"},{"id":"27","name":"MMA"},{"id":"17","name":"Mount"},{"id":"30","name":"North South Position"},{"id":"29","name":"Self Defense"},{"id":"18","name":"Side Control"},{"id":"28","name":"Strikes"},{"id":"20","name":"Theory & Discussions"},{"id":"9","name":"Throws"},{"id":"22","name":"Wrist Locks"}]}"
It seems that the API you’re requesting requires authentication, and you’re not logged in from the PHP code, while you are in the browser.