Php $\u会话变量不在文件之间传递
我有一个登录脚本,它将用户详细信息放入会话变量中。今天我把网站移到了一个新的主机上,现在我的代码不起作用了。这是我能做的最好的了,但它仍然不起作用 main_login.php:Php $\u会话变量不在文件之间传递,php,session,Php,Session,我有一个登录脚本,它将用户详细信息放入会话变量中。今天我把网站移到了一个新的主机上,现在我的代码不起作用了。这是我能做的最好的了,但它仍然不起作用 main_login.php: (script above here gets all the $info from the database. So far it is working) if($count==1){ session_start(); $_SESSION['username'] = $info['username']
(script above here gets all the $info from the database. So far it is working)
if($count==1){
session_start();
$_SESSION['username'] = $info['username'];
$_SESSION['given'] = $info['given_name'];
$_SESSION['family'] = $info['family_name'];
$_SESSION['profile'] = $info['profile'];
$_SESSION['adultchild'] = $info['adultchild'];
$_SESSION['id'] = $info['id'];
header("location:welcome.php");
}
welcome.php:
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
session_start();
if(!isset($_SESSION['username'])){
header("location:main_login.php");
}
问题是,当我打印任何会话变量时,什么都不会发生。我甚至尝试过做一个var\u转储($\u SESSION)
,但结果是一个空数组。坦白地说,我花了一整天的时间在这上面,我被卡住了
session_start();
if(!isset($_SESSION['username']));
header("location:main_login.php");
}
改为:
session_start();
if(!isset($_SESSION['username'])){
// ^ typing mistake
header("location:main_login.php");
}
如果启用了会话支持,请检查您的配置;如果设置了
PHPSESSID
cookie,请检查您的cookie。可能它没有输入您的if($count==1),没有其他解释说明数组为空。您可能将cookie域设置错误,因此发送cookie,但是浏览器拒绝接受/发送cookie,因为域不是正确的域。我如何更改cookie的内容?就像在cookie域和thatah抱歉刚才检查了一下,这是我复制到这里时的一个打字错误