当用户登录会话以 php 和 mysql 开始时,我试图显示“活动”或“非活动”。问题是,即使我尝试使用状态为“非活动”的帐户登录,它也会一直显示“活动”状态。我已经添加了 session_start(); 在页面的开头。
这是我的登录代码的一部分:
$sql = "SELECT * FROM `users_tmp` WHERE uidUsers=? OR emailUsers=?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)){
header("Location: ..index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $password);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = $row['pwdUsers'];
if($pwdCheck == false){
header("Location: ../index.php?error=wrongpwd");
exit();
} else if ($pwdCheck == true) {
session_start();
$_SESSION['userId'] = $row['idTmp'];
$_SESSION['idTmp'] = $row['idTmp'];
$_SESSION['stateUser'] = $row['stateUser'];
header("Location: ../user/perfil.php?login=success");
exit();
}
}
else{
header("Location: ../index.php?error=wrongpwds");
exit();
}
这是我要显示的内容:
<?php if(isset($_SESSION['idTmp']) ){
$state = $_SESSION['stateUser'];
if($state = "Active"){
echo $state;}
elseif($state = "Inactive"){
echo $state ;}
}
else{echo'nothing';}?>
米琪卡哇伊