在您将此标记为重复之前,我已经通读了有关此主题的所有答案,但没有一个对我有用,这就是我发布此内容的原因。
所以问题是 $_SESSION 的数据没有逐页保存。这是我的测试:
TestOne.php
<?php
session_start();
$_SESSION["user_id"] = 1;
if(isset($_SESSION["user_id"])) {
header("Location: TestTwo.php");
}
?>
TestTwo.php
<?php
if(isset($_SESSION["user_id"])) {
echo $_SESSION["user_id"];
}
?>
它转到第二页,但它是一个空白页。为什么数据不逐页保存? php.ini 中的 session_save 设置为/tmp(我使用的是 hostgator)
最佳答案
您的 TestTwo.php
缺少 session_start();
仅供引用:如果您正在使用 session ,则需要对所有 PHP 文件调用 session_start();
。
I have read through all the answers on this topic and Non of them worked for me, this is why I am posting this.
顺便说一句,真的引起了我的注意。
关于PHP - session 变量不在页面之间保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20300342/