【问题标题】:Verify account status验证帐户状态
【发布时间】:2013-11-15 11:12:19
【问题描述】:

我正在尝试检查帐户状态是否已验证。这是通过 Mysql 表中的 ENUM 列完成的。我已经能够将状态更改为已验证的“是”,但似乎无法检查它是“是”还是“否”。我尝试了以下代码的不同方式,但无济于事。提前谢谢大家。

<?php
ob_start();
session_start();
include '/home/wc002/include/dbconnect.php';

if (isset($_POST)) {
    $username  = strip_tags(trim($_POST['myusername']));
    $password = strip_tags(trim($_POST['mypassword']));
    $username = mysqli_real_escape_string($conn, $username);

    // Register $myusername, $mypassword
    $_SESSION["myusername"] = $username;
    $_SESSION["mypassword"] = $password;

    //Check if account is Verified
    //$query ="SELECT Verified FROM Member WHERE Verified = false;";
    //$check = mysqli_query($conn, $query);

    //if ($check == true){
    //  echo "Please Verfiy your account";
    //}
    //else{

    //Check username matches
    $query1="SELECT `Password`, `salt` FROM `Member` WHERE `Username`='$username'";
    $result1 = mysqli_query($conn, $query1);

    if(mysqli_num_rows($result1) == 0) // User not found. So, redirect to TwitchMain.php   again.
    {
        die(header("location:TwitchMain.php?loginFailed=true&reason=blank"));
    }

    $userData = mysqli_fetch_array($result1, MYSQL_ASSOC);
    $hash = hash('sha256', $userData['salt'] . hash('sha256', $password));

    //Incorrect password. So, redirect to TwitcMain.php again.
    if($hash != $userData['Password']) 
    {
        die(header("location:TwitchMain.php?loginFailed=true&reason=password"));
    } else { 
   // Redirect to home page after successful login.
        header('Location: Twitch.php');
    }
}
?>

【问题讨论】:

  • 如果您采用注释掉的代码,就像您从数据库中读取行的方式一样,就像您对 Member 表所做的那样? $check 是一个 mysqli 资源标识符,您可以从其中首先检索带有 mysqli_fetch_array(... 的结果集?

标签: php mysql


【解决方案1】:

为你的读数添加一个条件,如果你的列名是'ENUM',成功后检查 if ($userData['ENUM'] == 1)。

   if($hash != $userData['Password']) 
    {
        die(header("location:TwitchMain.php?loginFailed=true&reason=password"));
    } else { 
   // Redirect to home page after successful login.
        if ($userData['Verified'] == 'YES'){
            header('Location: Twitch.php');
        } else {
            die('account not activated');
        }
    }

【讨论】:

  • 感谢您的输入 ..Column is name is Verified the type is ENUM
  • 感谢 Fyntasia 将 ENUM 更改为 Verifed 并将 == 1 更改为 'YES'.. 工作感谢伙伴 :)
  • 为清晰起见进行了编辑,很高兴为您提供帮助!
猜你喜欢
  • 1970-01-01
  • 2014-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-13
  • 1970-01-01
  • 2011-03-14
  • 1970-01-01
相关资源
最近更新 更多