我有一个登录脚本,可以将用户详细信息放入会话变量中。今天我把网站搬到了一个新的主机,现在我的编码不起作用了。这是我能做的最好的,但它仍然不起作用
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'];
$_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_dump($_SESSION)
,但它出现了一个空数组。坦率地说,我整天都花在这上面而且被卡住了。
答案 0 :(得分:1)
session_start();
if(!isset($_SESSION['username']));
header("location:main_login.php");
}
更改为:
session_start();
if(!isset($_SESSION['username'])){
// ^ typing mistake
header("location:main_login.php");
}