我在 login.php 中有这段代码
if ( $sth->execute() ) {
$row = $sth->fetch(PDO::FETCH_ASSOC);
if ( $row ) {
var_dump($row); // See below
$_SESSION['login'] = $row['login'];
setcookie('login', $row['login'], time() * 7 * 24 * 60 * 60);
if ( $row['right'] == ACCESS_ADMIN ) {
echo "true"; // true
$_SESSION['right'] = ACCESS_ADMIN;
setcookie('right', $row['login'], time() * 7 * 24 * 60 * 60);
}
}
}
var_dump($row) - array(3)
{
["login"]=> string(6) "phplox"
["password"]=> string(32) "827ccb0eea8a706c4c34a16891f84e7b"
["right"]=> string(5) "admin"
} ?>
<br>
好的没问题。转到 index.php。
<?php var_dump($_COOKIE) ?> `// array(1) { ["PHPSESSID"]=> string(26) "o05mr9luc2ok8ieadss4v9mhg0" }`
但如果
<?php var_dump($_SESSION) ?> //
结果是:
array(3)
{
["request_token"]=> string(32) "335f1dcd4283889f0f2fe602cfa36d71"
["login"]=> string(6) "phplox" ["right"]=> string(5) "admin"
}