会话变量并置于if else下

时间:2014-02-02 19:38:25

标签: php

这段代码有问题吗?当otp!= rand时,页面往往显示echo "<script>alert('Too many failures. Please login again.'); location.href='login.php';</script>";即使尝试&lt; 3.我该如何解决这个问题? :(

if ($otp == $rand) {
//$query = "SELECT * FROM user WHERE user_id='$user_id' AND otp='$otp'";
//$result = mysqli_query($link, $query) or die(mysqli_error($link));
echo "<script>location.href='viewAccountBalance.php'</script>";
} 

else if ($otp != $rand)  {
  $_SESSION['attempts']++;
  if ($_SESSION['attempts'] < 3){
       echo "<script>alert('You have keyed in an invalid iBanking OTP. Please try again.');location.href='loginOtp.php'</script>";
  } 
  else{
       echo "<script>alert('Too many failures. Please login again.'); location.href='login.php';</script>";
  }
}
}

2 个答案:

答案 0 :(得分:0)

试试这个,

$_SESSION['attempts'] = $_SESSION['attempts']+1;

答案 1 :(得分:0)

这也发生在我身上。我不知道会发生这种情况,但这对我有用

$_SESSION['attempts']++;

$_SESSION['attempts'] = $_SESSION['attempts'] + 1;