I have this JSON an I want to get just license_key.
{"data": {"enabled": true,"product_link": "example","license_key": "BS7X4-55UH7-ZG2EV-ME2N5","buyer_email": "[email protected]","uses": 0,"date": "2022-11-11T20:56:37+00:00"}}
I try this script but when i open it I get white page
<?php
$url = "https://example.com/";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($curl);
curl_close($curl);
$json_decoded = json_decode($resp);
$license_key = '';
for ($i = 0; $i < count($json_decoded->{'data'}); $i++) {
$license_key = $json_decoded->{'data'}[$i]->{'license_key'};
}
echo $license_key;
3
Answers
You probably have a white page because your script has an error (perhaps curl extension is not installed/enabled) and your PHP settings have error reporting disabled.
You can try enabling error reports by adding this at top of your code:
Or if that doesn’t work, find a php.ini file and enable errors:
If you are confused about how to do any of this, you will have to search for how to enable error reporting for your hosting system and web server.
For your JSON with the following format (which does NOT contain any square brackets in any levels)
You simply need
$json_decoded->{'data'}->{'license_key'};
to get the license keySo amend to
You may visit the following sandbox link for the result:
http://www.createchhk.com/SOanswers/subf/1.php
Setup debugging in your development environment will help you best.
Video
In the browser activate debugging, in VSCode start the debugger. This way you can set breakpoints, read variables live and step through your code.