在数据库中成功验证用户('email'和'pass')后,我需要检查用户'status'(1 = True),如果确定用户是'admin'则是真的(1 = True)并相应地重定向他。先感谢您! P. S.引用的单词是确切的表名。
代码如下(一切正常,除了这两个步骤):
$errors = array(); // Initialize error array.
// Validate the email address:
if (empty($email)) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = mysqli_real_escape_string($dbc, trim($email));
}
// Validate the password:
if (empty($pass)) {
$errors[] = 'You forgot to enter your password.';
} else {
$p = mysqli_real_escape_string($dbc, trim($pass));
}
if (empty($errors)) { // If everything's OK.
// Retrieve the user_id and first_name for that email/password combination:
$q = "SELECT user_id, first_name FROM users WHERE email='$e' AND pass=SHA1('$p')";
$r = @mysqli_query ($dbc, $q); // Run the query.
// Check the result:
if (mysqli_num_rows($r) == 1) {
// Fetch the record:
$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
// Return true and the record:
return array(true, $row);
} else { // Not a match!
$errors[] = 'The email address and password entered do not match those on file.';
}
} // End of empty($errors) IF.
// Return false and the errors:
return array(false, $errors);
} // check_login()函数结束。