【发布时间】:2021-02-19 18:23:09
【问题描述】:
每次我将应用程序部署到谷歌应用程序引擎时,我都会遇到同样的问题:从同一网站中的一个页面转到另一个页面时,我的会话变量消失了。在我的本地主机上运行我的应用程序时我没有这个问题,所以我相信这是因为错误的 GAE 配置(我是 GAE 的新手)。
我将在这里展示我的一个项目:
app.yaml:
runtime: php73
# Defaults to "serve index.php" and "serve public/index.php". Can be used to
# serve a custom PHP front controller (e.g. "serve backend/index.php") or to
# run a long-running PHP script as a worker process (e.g. "php worker.php").
#
# Serve your app through a front controller at index.php or public/index.php.
runtime_config:
document_root: .
handlers:
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg|css|js|map|PNG|svg))$
static_files: \1
upload: .+\.(gif|png|jpg|css|js|map|PNG|svg)$
- url: /.*
script: auto
index.php:
<?php
ini_set('allow_url_fopen',1);
switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {
case '/':
require 'first.php';
break;
case '/first.php':
require 'first.php';
break;
case '/first':
require 'first.php';
break;
case '/second.php':
require 'second.php';
break;
case '/second':
require 'second.php';
break;
default:
require 'first.php';
break;
}
?>
first.php:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>fisrt</title>
</head>
<body>
<h1>first</h1>
<?php
session_start();
$_SESSION['id'] = 123;
$_SESSION['nombre'] = 'franc';
?>
<script>
window.location.href="second.php";
</script>
</body>
</html>
second.php:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Second</title>
</head>
<body>
<h1>Second</h1>
<?php
session_start();
echo $_SESSION['id'];
echo $_SESSION['nombre'];
?>
</body>
</html>
在我的本地主机中,当我运行此项目时,它按预期工作:索引处的前端控制器重定向到 first.php。 first.php 创建会话变量并重定向到 second.php。最后 second.php 打印出会话变量中的值。
但是,当我将相同的项目部署到 GAE 时,它会显示没有会话变量的 secon.php 页面: image of second.php at GAE
PD:我只是在没有数据库实例的谷歌应用引擎上部署项目。
【问题讨论】:
标签: php google-app-engine session-variables