How to update Firebase Database from a PHP script on Heroku?

104
October 22, 2018, at 08:20 AM

I am working on updating my firebase database using PHP. I have the following code working fine on my local server. But when I push my project to Heroku servers I get an HTTP 500 error.

<?php
header("Content-Type:application/json");
if (!isset($_GET["token"]))
{
echo "Technical error";
exit();
}
if ($_GET["token"]!='1234567890')
{
echo "Invalid authorization";
exit();
}
if (!$request=file_get_contents('php://input'))
{
echo "Invalid input";
exit();
}


require_once './vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/kshdkhalsdhf77^&5/adfy-9ee95-815198ad0dcc.json');
$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();
$database = $firebase->getDatabase();
$newPost = $database
    ->getReference('Users/user1')
    ->push([
        'Amount' => 200,
        'Phone Number' => 000000
    ]);


 echo '{"ResultCode":0,"ResultDesc":"Confirmation received successfully"}';
?>

I was trouble shooting the code and found out that the problem starts just right at the require statement. If I comment out the code that gets the Firebase database everything works and the HTTP 500 error goes away.

How can I solve this?

READ ALSO
How would I splice a 2D array in P5JS or delete an element within it?

How would I splice a 2D array in P5JS or delete an element within it?

I am making a game and it has a 2D array which holds all of the terrain's data and when I click on a block I want it to delete from the array but I don't know how to splice a 2D array?

128
Understanding &ldquo;post/redirect/get&rdquo; [closed]

Understanding “post/redirect/get” [closed]

I am having a very hard time understanding the exact process of "post/redirect/get"I have combed through this site and the web for several hours and cannot find anything other than "here's the concept"

116