I am facing a weird problem with file_get_contents and decoding to json the result. I have to tell you that this code was fully functional in other server.
I am trying to decode this json: http://mediarupt.com/GET/categorized_services_for_supplier.php?suppliersID=10
into this page: http://mediarupt.com/kostas.php
The code for kostas.php is this:
<?php
$servicesJSON = file_get_contents("http://mediarupt.com/GET/categorized_services_for_supplier.php?suppliersID=10");
$ForeignKeys = (object)array();
$ForeignKeys->ServicesList = json_decode($servicesJSON, true);
echo "error: " . json_last_error();
?>
<select name="servicesID" id="servicesID">
<option id="serviceID_0" value="0" rel="0" style="font-style:italic;">Select a category...</option>
<?php foreach($ForeignKeys->ServicesList['categorized_services'] as $value){ ?>
<option id="serviceID_<?=$value['servicesID']?>" value="<?=$value['servicesID']?>" rel="<?=$value['hasStoresList']?>"><?=$value['serviceName']?></option>
<?php } ?>
</select>
<?php
echo '<br><br>The result of file_get_contents ($servicesJSON): '.$servicesJSON;
?>
Code for categorized_services_for_supplier.php:
<?php header('Content-Type: application/json');
require('../settings/dbli.php');
$table = array();
$suppliersID = "0";
if(isset($_GET['suppliersID']) && $_GET['suppliersID']!=NULL && $_GET['suppliersID']!='' ){ $suppliersID = $SQLConn->real_escape_string($_GET['suppliersID']); }
$query = "SELECT DISTINCT Services.servicesID, serviceName, servicePrice, hasStoresList FROM Services, ServicesList WHERE Services.servicesID = ServicesList.servicesID AND suppliersID = '$suppliersID' AND status = '1' AND deleted = '0'";
$result = $SQLConn->query($query);
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$tempArray = array();
foreach($row as $key => $value){
$tempArray[$key] = $value;
}
array_push($table,$tempArray);
}
$arr = array( "categorized_services" => $table);
echo json_encode($arr);
?>
I receive error 4 as latest json error, which means that I have JSON_ERROR_SYNTAX. But I validate the json result with http://jsonlint.com/ and all seems to be ok.
Also, both pages are UTF-8 with BOM disabled. You can access php configurarion here: http://mediarupt.com/phpinfo.php
I hope to find the solution...
Thank you in advance