这是我设置会话变量的地方。
function validateUser()
{
session_regenerate_id (); //this is a security measure
$_SESSION['user'] = $_POST['username'];
$_SESSION['valid'] = 1;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
}
这就是print_r($ _SESSSION)回声。
Array ( [user] => aboshart [valid] => 1 [firstname] => [lastname] => )
如果我回显$ firstname和$ lastname,我会得到正确的值。我做错了什么?
答案 0 :(得分:3)
您没有将$ firstname或$ lastname传递给该函数。
function validateUser($firstname, $lastname)
{
session_regenerate_id (); //this is a security measure
$_SESSION['user'] = $_POST['username'];
$_SESSION['valid'] = 1;
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
}
$ _ POST和$ _SESSION应该在范围内,但其他的不是