0

该项目旨在获取一些用户输入并检查连接的 Google Datastore 是否匹配。当使用一切托管时,dev_appserver.py一切都按预期工作。

实时版本不是这种情况,使用gcloud app deploy. 尝试检索实体时会出现问题,使用它的键作为lookup.

<?php
require __DIR__ . "/vendor/autoload.php";

use Google\Cloud\Datastore\DatastoreClient;

$datastore = new DatastoreClient([
"projectId" => "54327567209-project"
]);

// Retrieving user entities
function lookup_user(DatastoreClient $datastore, string $id) {
  $key = $datastore->key("user", $id);
  $user = $datastore->lookup($key);
  return $user;
}

// Validation
$authErr = "";
$id = $pword = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // Existence check
  if (!empty($_POST["id"]) && !empty($_POST["password"])) {
    $id = $_POST["id"];
    $pword = $_POST["password"];
    // Attempt to get user from Google Cloud
    $user = lookup_user($datastore, $id); // <---- Error happens here
    // Check if user exists and password matches
    if (!empty($user["name"]) && $user["password"] == $pword) {
      // Removed for debugging
    } else {
      // Id or password authentication fail
      $authErr = "User id or password is invalid";
    }
  } else {
    // Missing id or password
    $authErr = "User id or password is invalid";
  }
}
?>

<!DOCTYPE html>
<html>
  <head>
    <style>
      .error {color: #FF0000;}
    </style>
  </head>
  <body>
    <h2>Account Access</h2>
    <form method="post" action="">
      <div>Username: <input name="id" type="text"></input></div>
      <div>Password: <input name="password" type="password"></input></div>
      <div><input type="submit" value="Login"></div>
      </br>
      <span class="error"><?php echo $authErr; ?></span>
    </form>
  </body>
</html>

页面在尝试进行查找时变为空白,类似于 running exit()。我看不到任何错误消息。我想知道是否可以打开某种日志记录来帮助解决这个问题。

4

1 回答 1

0

问题出在lookup_user()功能上。删除此函数并内联粘贴相同的代码解决了该问题。

于 2020-04-02T15:06:51.533 回答