我正在尝试检查帐户状态是否已经过验证。这是通过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');
}
}
?>
答案 0 :(得分: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');
}
}