0

I get error reading data from json source, I get a blank page error.

I am making a mistake.

I just want to get the category BetTypeId = 3.

Could you help?

 <?php
error_reporting(1);
header("Content-type: text/xml; charset=utf-8");
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.misli.com/scripts/BetList.aspx?action=get&BetTypeId&3",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  //CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
  ),
));
$ok = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
echo "<Maclar>";

                if($ok->BetTypeId=="3")
                {
                $tarih = $ok->CloseDate;
                $ulke = $ok->CountryName;
                echo '<ulke="'.$ulke.'" tarih="'.$tarih.'" />'; 
                }
    echo "</Maclar>";
}
?>
Mert Fırat
  • 15
  • 2
  • 8

1 Answers1

0

The target site you want to fetch data will check the browser agent.

Add the agent and fix the problem pointed out by Scuzzy, then your code will work.

You could refer the following code. Please note there may be error of your xml format, that will cause the browser doesn't display the response data normally. But I did get the response <Maclar><ulke="Şampiyonlar Ligi" tarih="2018-02-13T22:45:00" /></Maclar>

The code:

<?php
error_reporting(1);
header("Content-type: text/xml; charset=utf-8");
$agent= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36';

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.misli.com/scripts/BetList.aspx?action=get&BetTypeId&3",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_USERAGENT=>$agent,
CURLOPT_HTTPHEADER => "accept: application/json"
));

$ok = curl_exec($curl);
//echo $ok;
$ok = json_decode($ok);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} 
else {
    echo "<Maclar>";

    if($ok[0]->BetTypeId=="3")
    {
        $tarih = $ok[0]->CloseDate;
        $ulke = $ok[0]->CountryName;
        echo '<ulke="'.$ulke.'" tarih="'.$tarih.'" />'; 
    }
    echo "</Maclar>";
}
?>

Hope it helps.

Phil
  • 1,444
  • 2
  • 10
  • 21
  • Thank you so much for your interest, Phil. again a blank page comes up :( I can not figure out where I'm making the mistake ... – Mert Fırat Dec 26 '17 at 09:39
  • You could check the source code of your page. The response data are right there. As I mentioned, your xml formt may be not good, so it won't display the result in browser. – Phil Dec 26 '17 at 10:10
  • Thank you very much, Phil. I have a very small problem right now, in the json array source "." var and Parse error b>: syntax error, unexpected '.1' (T_DNUMBER). $ ev = $ cok-> bets-> F.1-> OV; (Point after F) – Mert Fırat Dec 27 '17 at 09:27
  • Did you use exactly the same code? I just check and the code remains working fine. If you changed some code, please post it here and let us check. – Phil Dec 27 '17 at 11:14