if 会话数据 codeigniter 上的语句 [英] if statement on session data codeigniter
问题描述
所以我试图隐藏或显示用户是否登录的选项.
So I am trying to hide or show options if the user is logged in or not.
我有一个简单的声明,无论我是否登录,它总是显示否.
I have this simple statement, its always showing no regardless if I am logged in or not.
if( !isset($_SESSION) ){
echo "yes";
}
else {
echo "no";
}
我也试过
function __construct()
{
parent::__construct();
$this->is_logged_in();
}
if(is_logged_in())
{
echo "yes";
}
else
{
echo "no";
}
都不行,我也认为第一个更简单,但我不确定哪种方法会更好.
Neither works, I also think the first one if simpler, but I am not sure what method would be better.
推荐答案
isset($_SESSION)
检查变量是否设置,这里 $_SESSION
已经设置定义.
isset($_SESSION)
checks if the variable is set or not and here $_SESSION
is already defined.
所以在你的情况下 !(isset($_SESSION))
是 false
因为 isset($_SESSION)
是真的并且 !true
是 false
so in your case !(isset($_SESSION))
is false
coz isset($_SESSION)
is true and !true
is false
要检查会话值,请尝试 isset($_SESSION['key_you_set'])
.这将检查 key_you_set
是否存在.
To check for the session value try isset($_SESSION['key_you_set'])
. This will check if the key_you_set
exists or not.
这篇关于if 会话数据 codeigniter 上的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!