大家好,我正在制作一個注冊/登錄網站作為一個學習和練習專案,我正在使用一個教程:https ://www.youtube.com/watch?v=LC9GaXkdxF8&t=5768s&ab_channel=DaniKrossing
現在一切正常,我沒有收到任何語法錯誤,但是當我使用用戶名/電子郵件和密碼登錄時,它必須將我重定向到 ../index.php?login=success 頁面,但它沒有,它一直在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();
}
從現在開始非常感謝。
uj5u.com熱心網友回復:
<?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();
}
}
uj5u.com熱心網友回復:
如果要使用頁眉,<?php ob_start();?>請在頁面頂部和頁面<?php ob_end_flush();?>底部鍵入。
uj5u.com熱心網友回復:
驗證表單中提交的輸入型別是否具有以下屬性:
name="login-submit"&value="submit"
因為您可以重定向到的唯一方法index.php是:
if (isset($_POST['login-submit'])) // is FALSE
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/429448.html
