【发布时间】:2013-03-26 00:40:43
【问题描述】:
我在我的网站上登录时将用户 ID 设置为会话。在设置后不久回显会话变量时,它会显示出来。但之后我将其重定向到另一个页面,其中会话被设置,然后检查会话.但它显示未定义索引user_id的错误消息。此代码在localhost中工作,也在服务器上工作。但现在它显示错误。由于设置会话的问题,无法登录网站。
$_SESSION['user_id'] = $user_id;
header('location:home.php');
在 home.php 中
include('session.php');
在 session.php 中
session_save_path('include/session_store');
session_start();
if(!(isset($_SESSION['user_id'])))
{
header('location:signin.php');
}
根据其他 stackoverflow 用户的建议,我尝试了这个。创建了一个 test.php 文件。
session_save_path('include/session_store');
session_start();
$_SESSION['yahoo'] = 'yahoo';
header('location:test2.php');
在test2.php中
session_save_path('include/session_store');
session_start();
echo $_SESSION['yahoo'];
现在在 localhost 中打印 yahoo。但在服务器中,显示空白屏幕。session_store 文件夹也包含一些 0kb 文件。
【问题讨论】:
-
在
header('location:home.php')的文件中,有session_start()吗? -
你在
home.php文件上写了session_start吗? -
提示:在
header()之后写上exit(); -
我已经在 session.php 中添加了 session_start,那么是否需要在 home.php 中单独启动 session?
-
请您的服务器人员在服务器上设置会话路径。如果同一页面在本地主机上而不是在服务器上运行,则可以肯定服务器无法与会话相同。