php - 如果用户输入了错误的登录信息,登录验证会显示警报
问题描述
当用户输入错误的用户名和密码时,我需要回显或显示警告框。如果用户输入了错误的用户名或错误的密码,我同时使用 url 来显示状态。
session_start();
if (isset($_POST['submit'])) {
include 'dbh.inc.php';
$uid = mysqli_real_escape_string ($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string ($conn, $_POST['pwd']);
//ERROR HANDLERS
//Check for empty fields
if (empty($uid) || empty($pwd)) {
header("Location: ../login.php?login=empty");
exit();
} else {
$sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck < 1) {
header("Location: ../login.php?username_not_found");
exit();
} else {
if ($row = mysqli_fetch_assoc($result)) {
//De-hashing the password
$hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
if ($hashedPwdCheck == false) {
header("Location: ../login.php?password_not_match");
exit();
} elseif ($hashedPwdCheck == true) {
//Log in the user here
$_SESSION['u_id'] = $row['user_id'];
$_SESSION['u_first'] = $row['user_first'];
$_SESSION['u_last'] = $row['user_last'];
$_SESSION['u_email'] = $row['user_email'];
$_SESSION['u_uid'] = $row['user_uid'];
header("Location: ../apptableremarks.php?login=success");
exit();
}
}
}
}
} else {
header("Location: ../index.php?login=error");
exit();
}
解决方案
首先改变这一行
header("Location: ../login.php?login=notFound");
然后在 index.php 文件的页面顶部写下这段代码
if(isset($_GET['login']))
{
echo "user name not found";
}
推荐阅读
- excel - 有没有办法循环遍历类属性来填充它们?
- javascript - Alfresco javascript 获取自定义 DataList 的属性
- spring - 在SpringBoot中如何确保@Async method1在@Asyn method2之前执行?
- listview - CollectionView 嵌套到 ListView
- jquery - 弹出表单中的 Ajax 发布
- apache-spark - DataFrameReader 在读取 avro 文件时抛出“不支持的类型 NULL”
- jquery - Angular 6中jQuery数据表回调方法的单元测试
- python - 将布尔时间线绘制为水平条形图
- rpmbuild - rpmbuild 我没有指定的依赖项来自哪里?
- mongodb - 如何使用 Mongodb 验证器验证非空字段