会话出现奇怪的问题
我遇到了这个奇怪的问题,我终于意识到这是由于我确定用户是否登录的单个会话所致。 ($_SESSION['uID']) 一切都工作正常,直到突然间这个会话在我的一个文件中不可用!我的意思是它仍然可以在我的本地主机上运行,但当我尝试在我的实际服务器上访问它时就不行了。
如果会话存储在某些文件中,我怀疑服务器可能存在问题,如果是这样,为什么会话仅在我的一个文件中不可用?
编辑:问题是不是session_start(),因为我的文件中已经有它了。如果我为此会话使用另一个名称,它会再次工作。
编辑2:这个人(此处:页面之间的会话被擦除) 似乎也有同样的问题,但正如你所看到的,他也得不到答案。有人吗?
编辑 3:以下是工作文件和有问题的文件的示例:
会话 uID 在此文件中可用:
<?php
session_start();
if (!empty($_SESSION['username'])) { // USER Active - SESSION Active
$userLoggedIn = "1"; // login flag
$uID = $_SESSION['uID']; // here it returns a valid value
dbconnect();
// and the rest (this file works ok)
}
?>
并且在以下文件中不可用
<?php
// Jan 2012
session_start();
if (!empty($_SESSION['username'])) { // SESSION Active
$userLoggedIn = "1"; // login flag
$pID = ""; // initiating
$uID = "";
$NewStat = "1";
$pID = $_POST['pID'];
$uID = $_SESSION['uID']; // This is were it returns null!
// on direct use die
if (!$pID || !$uID || $pID == "" || $uID == "") die("ERROR 33");
require_once ("./functions.php");
dbconnect();
// Getting info from db and stuff...
echo $starFile;
} else {
die("ERROR sd23");
}
?>
I had this weird issue and I finally realized that it was due to a single session by which I determined whether the user's logged in or not. ($_SESSION['uID']) Everything was working alright until all of a sudden this very session was unavailable in ONLY ONE of my files! I mean it still worked on my localhost but not when I tried to reach it on my actual server.
If sessions are stored in some files, I suspect there might be an issue with the server and still if so, why the session is not available in ONE of my files only?
Edit: The problem is not session_start() as I already have it on my file(s). If I use another name for this session it works again.
Edit 2: This guy (Here: session wiped out between pages) seems to have the same issue but as you can see he could get no answer either. Anyone?
Edit 3: Here's a sample of both working and problematic files:
Session uID is available in this file:
<?php
session_start();
if (!empty($_SESSION['username'])) { // USER Active - SESSION Active
$userLoggedIn = "1"; // login flag
$uID = $_SESSION['uID']; // here it returns a valid value
dbconnect();
// and the rest (this file works ok)
}
?>
And it is not available in the following file
<?php
// Jan 2012
session_start();
if (!empty($_SESSION['username'])) { // SESSION Active
$userLoggedIn = "1"; // login flag
$pID = ""; // initiating
$uID = "";
$NewStat = "1";
$pID = $_POST['pID'];
$uID = $_SESSION['uID']; // This is were it returns null!
// on direct use die
if (!$pID || !$uID || $pID == "" || $uID == "") die("ERROR 33");
require_once ("./functions.php");
dbconnect();
// Getting info from db and stuff...
echo $starFile;
} else {
die("ERROR sd23");
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不在该文件中调用
session_start()
,就会发生这种情况。This will happen if you don't call
session_start()
in that file.