不显示回声..PHP

  • 本文关键字:PHP 回声 显示 php
  • 更新时间 :
  • 英文 :


每次标头重定向后我都有一个回声。但它不会弹出。因此,当用户输入无效的登录详细信息时,不会弹出任何消息。我做错了什么? 我也尝试了JavaScript方法,但没有设法解决问题。 这是否与我的嵌套ifs有关?

<?php
session_start();
#first if
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 if this input are empty
#second if
if (empty($uid) || empty($pwd)) {
header("Location: ../index.php?login=empty");
exit();
}/*second else*/ else {
$sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
$result = mysqli_query($conn,$sql);
$resultCheck = mysqli_num_rows($result);
#third if
if ($resultCheck < 1) {
header("Location: ../index.php?login=error");
echo "Login error";
exit();
}/*third else*/ else {
#forth if
if ($row = mysqli_fetch_assoc($result)) {
//de-hashing the password
$hashedPwdCheck = password_verify($pwd , $row['user_pwd']);
#fifth if
if ($hashedPwdCheck == false) {
header("Location: ../index.php?login=error");
echo "Login error";

exit();
} /*fifth else*/ 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'];
$uid = $_SESSION['u_id'];
header("Location: ../index.php?login=success");
echo "Login error";
exit();
}
}
}
}
}/*first else*/ else {
header("Location: ../index.php?login=error");
echo "Login error";
exit();
}
?>

如果使用location标头,则永远无法显示消息 - 浏览器会忽略请求的其余部分并立即执行重定向,因为HTTP代码已更改为302。

即使你可以显示一条消息,这对用户来说也不是一个好的体验,因为它只会显示几分之一秒,然后会发生重定向并且页面将被覆盖。您应该在登录页面上显示错误消息(index.php?login=error(。

最新更新