首页 > 解决方案 > 将firestore中的数据放入下一个php文件

问题描述

我在 cloud firestore 中有几个值,并且想要访问每个变量。因此我这样做我的代码

<?php

require __DIR__.'/vendor/autoload.php';

use Google\Cloud\Firestore\FirestoreClient;

$db = new FirestoreClient(
    [
        'projectId' => 'fakedata-aa798'
    ]
);

$collectionReference = $db->collection('Test3');
$docRef = $collectionReference->document('User1');
$snapshot = $docRef->snapshot();

$Name= $snapshot['Name'];
$Contact= $snapshot['Contact no:'];
$Email= $snapshot['Email'];
$Location= $snapshot['Location'];
$Locationstatus= $snapshot['Location status'];
$Condition= $snapshot['Condition'];

session_start();
$_SESSION['Name'] = $Name;
$_SESSION['Contact no:'] = $Contact;
$_SESSION['Email'] = $Email;
$_SESSION['Location'] = $Location;
$_SESSION['Location status'] = $Locationstatus;
$_SESSION['Condition'] = $Condition;
?>

现在我想在下一个 PHP 文件中显示值,我使用 session_start 但仍然无法获取值

第 2 页

<?php
session_start();
                                        
echo $_SESSION['Name']; 
?>

有人能帮我吗?

标签: phpfirebasegoogle-cloud-firestore

解决方案


推荐阅读