php curl response not showing please help to fix. when I run this code I do not get any response from recharge.php file
JavaScript
x
<?php
// recharge url
$recharge_url = "http://localhost/api_system/recharge.php";
$key = "";
$number = "9134322935";
$operators = "ada";
$amount = "asa";
$FinalUrl = $recharge_url ."?key=".$key ."&number=" .
$number. "&op=" . $operators ."&amount=" . $amount;
$durl = curl_init($FinalUrl);
curl_setopt($durl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($durl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($durl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($durl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($durl, CURLOPT_URL, $FinalUrl);
curl_setopt($durl, CURLOPT_RETURNTRANSFER, true);
$resps = curl_exec($durl);
$res = json_decode($resps);
curl_close($durl);
echo "<pre>";
print_r($res);
?>
here is recharge.php file
JavaScript
<?php
if(isset($_GET['key'])){
}else{
echo json_encode(['status'=>'false','data'=>'API Hit Limit Exceed','result'=>'not']);
}
?>
Advertisement
Answer
try this code, hope it will help you— your current file —
JavaScript
<?php
$recharge_url = "http://localhost/test/recharge.php";
$key = "";
$number = "9134322935";
$operators = "ada";
$amount = "asa";
$FinalUrl = $recharge_url . "?key=" . $key . "&number=" . $number . "&op=" . $operators . "&amount="
. $amount;
$durl = curl_init($FinalUrl);
curl_setopt($durl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($durl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($durl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($durl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($durl, CURLOPT_URL, $FinalUrl);
curl_setopt($durl, CURLOPT_RETURNTRANSFER, true);
$resps = curl_exec($durl);
$res = json_decode($resps);
curl_close($durl);
echo "<pre>";
print_r($res);
?>
recharge.php
JavaScript
<?php
if (isset($_GET['key']) && $_GET['key'] != "") {
echo json_encode(['status' => 'true', 'data' => 'working', 'result' => 'not']);
} else {
echo json_encode(['status' => 'false', 'data' => 'API Hit Limit Exceed', 'result' => 'not']);
}
?>
and also you should put return/die/exit after echo statement to avoid the code execution after json_encode