通过PHP更新FIREBASE失败


updating FIREBASE over PHP fails

我遇到了一个问题,我尝试用CURL将JSON格式的数据更新到我的在线数据库:Firebase。一开始它工作得很好,但当我发送数据时,我已经发送了一些数据,之前它没有被存储。我正在发送一些GET变量的组合。

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);
}

谢谢!

这在理想情况下应该与getVariable一起使用。如果这不起作用,那么尝试将其映射到php中的变量,然后从中创建JSON。如果API不起作用。请试一下我在项目中使用过的下面一个,它也完全正常工作。

https://github.com/eldhosemjoy/firebase

我希望这个git也能帮助你理解firebase的操作。