检查记录的会话是否为真

时间:2014-05-18 18:32:21

标签: php

我有:header.php,register.php,login.php和profile.php

当用户登录时,我使用标题(位置:profile.php)将他重定向到profile.php

此外,在我进行重定向之前,我设置了一个会话:

$_SESSION['logged']= $user_email;

使用它,我想在header.php上做一个小技巧,比如:

    if(($_SESSION['logged'] == true) {
         echo "<a href="profile.php"> Logo </a>"; 
    } 
    else {
         echo "<a href="index.php"> Logo </a>";
   }

不知何故,这不起作用。我错过了什么?

1 个答案:

答案 0 :(得分:3)

您可以使用isset()函数

控制会话变量

尝试以下代码

session_start();
if(isset($_SESSION['logged'])){
  header("location:profile.php");
}
else{
  header("location:index.php");
}
相关问题