Php 使用 mysqli 进行登录重定向
Php login redirect with mysqli
大家好,我正在制作一个 signup/login 网站作为学习和实践项目,我正在使用一个教程:https://www.youtube.com/watch?v=LC9GaXkdxF8&t=5768s&ab_channel=DaniKrossing
目前一切正常,我没有收到任何语法错误,但是当我使用 username/email 和密码登录时,它必须将我重定向到 ../index.php?login=成功页面但是
它没有,它一直在 index.php page.I 找不到,如果你能帮助我,我很高兴收到你们的来信。
<?php
if (isset($_POST['login-submit'])) {
require 'dbh.inc.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql ="SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
$stmt =mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss",$mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == false) {
header("Location: ../index.php?error=wrongpwd");
exit();
}
else if ($pwdCheck = true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpwd");
exit();
}
}
else {
header("Location: ../index.php?error=nouser");
exit();
}
}
}
}
else {
header("Location: ../index.php");
exit();
}
从现在开始非常感谢。
如果您想使用页眉,请在页面顶部键入 <?php ob_start();?>
,在页面底部键入 <?php ob_end_flush();?>
。
验证表单中提交的输入类型是否具有以下属性:
name="login-submit"
& value="submit"
因为您可以重定向到 index.php
的唯一方法是 if :
if (isset($_POST['login-submit'])) // is FALSE
<?php
if (isset($_POST)){
if (isset($_POST['login-submit'])) {
require 'dbh.inc.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql ="SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
$stmt =mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss",$mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == false) {
header("Location: ../index.php?error=wrongpwd");
exit();
}
else if ($pwdCheck = true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpwd");
exit();
}
}
else {
header("Location: ../index.php?error=nouser");
exit();
}
}
}
}
else {
header("Location: ../index.php");
exit();
}
}
大家好,我正在制作一个 signup/login 网站作为学习和实践项目,我正在使用一个教程:https://www.youtube.com/watch?v=LC9GaXkdxF8&t=5768s&ab_channel=DaniKrossing
目前一切正常,我没有收到任何语法错误,但是当我使用 username/email 和密码登录时,它必须将我重定向到 ../index.php?login=成功页面但是 它没有,它一直在 index.php page.I 找不到,如果你能帮助我,我很高兴收到你们的来信。
<?php
if (isset($_POST['login-submit'])) {
require 'dbh.inc.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql ="SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
$stmt =mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss",$mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == false) {
header("Location: ../index.php?error=wrongpwd");
exit();
}
else if ($pwdCheck = true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpwd");
exit();
}
}
else {
header("Location: ../index.php?error=nouser");
exit();
}
}
}
}
else {
header("Location: ../index.php");
exit();
}
从现在开始非常感谢。
如果您想使用页眉,请在页面顶部键入 <?php ob_start();?>
,在页面底部键入 <?php ob_end_flush();?>
。
验证表单中提交的输入类型是否具有以下属性:
name="login-submit"
& value="submit"
因为您可以重定向到 index.php
的唯一方法是 if :
if (isset($_POST['login-submit'])) // is FALSE
<?php
if (isset($_POST)){
if (isset($_POST['login-submit'])) {
require 'dbh.inc.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql ="SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
$stmt =mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss",$mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if ($pwdCheck == false) {
header("Location: ../index.php?error=wrongpwd");
exit();
}
else if ($pwdCheck = true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpwd");
exit();
}
}
else {
header("Location: ../index.php?error=nouser");
exit();
}
}
}
}
else {
header("Location: ../index.php");
exit();
}
}