我相信我这样做是正确的,但它没有获取存储的cookie信息
的login.php
session_start();
$_SESSION['username'] = $user;
$_SESSION['password'] = $pass;
if(isset($_POST['remmemberme']))
{ ob_start();
setcookie("kitbusername", $_SESSION['username'], time()+60*60*24*100);
setcookie("kitbpassword", $_SESSION['password'], time()+60*60*24*100);
echo '<script>
window.top.location.href = "index.php";
</script>';
}
的index.php
<p class="welcome">Hello
<?php
session_start();
if($_COOKIE['kitbusername']){echo $_SESSION['username'];}
elseif($_SESSION['username']){
echo $_COOKIE['kitbusername'];
} else{
echo 'Guest';
}?>
</p>
的header.php
<?php session_start();
if(isset($_SESSION['username']) || isset($_COOKIE['kitbusername'])){
//Log Out Button// ?>
会话开始在所有页面上设置
答案 0 :(得分:1)
您没有在index.php上使用session_start()
致电ob_start()
后,您是致电ob_end_clean()
,ob_end_flush()
,ob_clean()
还是ob_flush()
?