使用会话来显示通知?

我想在用户登录时显示一条消息:

If the data is correct I will create the user session and other session named CORRECT and then check if this session exist for show the correct message:

首先,我创建会话:

$_SESSION['CORRECT'] = true;

现在我检查:

if($_SESSION['CORRECT']){
    echo = "Correct";
    $_SESSION['CORRECT'] = false;
}else{
    echo = "Incorrect";
}

我的问题是,会话验证是否正确?还是应该这样检查?:

if($_SESSION['CORRECT'] == true)
评论
  • 巢香莲
    巢香莲 回复

    1: if($_SESSION['CORRECT']){}

    2: if($_SESSION['CORRECT'] == true){}

    两者均可用于检查,但它们的用途不同

    if($_SESSION['CORRECT']){} will check that if($_SESSION['CORRECT']){} is present in the code or not and if($_SESSION['CORRECT'] == true){} will check whether the value of $_SESSION['CORRECT'] is equal to true.