【发布时间】:2020-02-25 14:35:46
【问题描述】:
我刚刚创建了 php web 服务器并将其连接到 firebase。当我尝试身份验证时,注册工作正常。但问题出在登录中。它不断收到此错误:
致命错误:未捕获错误:调用 /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php:24 中未定义的方法 Kreait\Firebase\Auth::signInWithEmailAndPassword() 堆栈跟踪:#0 {main } 在第 24 行的 /Applications/XAMPP/xamppfiles/htdocs/firebase_series/authActions.php 中抛出
这里是我的验证码:
<?php
include("includes/db.php");
if(isset($_POST['signup']))
{
$email = $_POST['emailSignup'];
$pass = $_POST['passSignup'];
$auth = $firebase->getAuth();
$user = $auth->createUserWithEmailAndPassword($email,$pass);
header("Location:index.php");
}
else
{
$email = $_POST['emailSignin'];
$pass = $_POST['passSignin'];
$auth = $firebase->getAuth();
$user = $auth->getUserWithEmailAndPassword($email,$pass);
if($user)
{
session_start();
$_SESSION['user'] = true;
header("Location:home.php");
}
}
?>
这是我的数据库连接代码:
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
use Kreait\Firebase\Auth;
// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyCHULFKW6Kl7FXZc3ZUTYL8fq0f90-kAJ0';
$firebase = (new Factory)
->withServiceAccount($serviceAccount, $apiKey)
// The following line is optional if the project id in your credentials file
// is identical to the subdomain of your Firebase project. If you need it,
// make sure to replace the URL with the URL of your project.
->withDatabaseUri('https://phpserver-f35e3.firebaseio.com/')
->create();
$database = $firebase->getDatabase();
?>
【问题讨论】:
-
这不会修复您的代码,但您使用了两次
if($user)。您需要删除其中之一。 -
是的,这只是一个错字。
-
你是如何在第一个 sn-p 中初始化 $firebase 变量的?
-
in index.php ``` ```
-
$email和$pass未在该else分支中设置
标签: php firebase firebase-realtime-database firebase-authentication xampp