2016-04-08 15 views
0

Ich habe ein Problem, ich habe versucht, JSON formatierte Daten mit CURL zu meiner Online-Datenbank: Firebase. Es funktioniert zunächst gut, aber wenn ich Daten, die ich gesendet habe, sende, bevor es nicht gespeichert wird. Ich sende eine Kombination einiger GET-Variablen.Aktualisierung FIREBASE über PHP schlägt fehl

if($_GET['user']!='') 
{ 
$user_url = str_replace('.' , ',' , $_GET['user']); 
$url='https://websitenew.firebaseio.com/' . $user_url . '.json'; 
$data = array('author'=>$_GET['user'], 'temp'=>$_GET['temp'], 'druck'=>$_GET['press'], 'notMoving'=>$_GET['move'], 'gpsx'=>$_GET['gpsx'], 'gpsy'=>$_GET['gpsy']); 
$data_json = json_encode($data); 
$header = array(
     'Content-Type: application/json', 
     'Content-Length: ' . strlen($data_json)); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH"); 
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); 
curl_exec($ch); 
curl_close($ch); 
} 

Vielen Dank!

Antwort

0

Dies sollte idealerweise mit Get Variable arbeiten. Wenn das nicht funktioniert, dann versuche es mit einer Variablen in PHP zu verknüpfen und dann ein JSON daraus zu erstellen. Wenn die API nicht funktioniert. Bitte probiere das folgende aus, das ich in meinem Projekt benutzt habe und es funktioniert auch.

https://github.com/eldhosemjoy/firebase

Ich hoffe, das git könnte Ihnen helfen, die Operationen mit Feuerbasis zu verstehen.