我正在按照教程在php中创建登录系统。这是我的登录脚本,当您填写电子邮件和密码进行登录之后。
<?php
if (isset($_POST['login-submit'])) {
//link maken met database
require 'dbh.inc.php';
$email = $_POST['mailuid'];
$pwd = $_POST['password'];
//zijn alle velden ingevuld?
if (empty($email) || empty($pwd)) {
header("location: ../index.php?error=emptyfields&email=".$email);
exit();
}
else{
$sql = "SELECT * FROM users WHERE emailUsers=?";
$stmt = mysqli_stmt_init($conn);
//check of de sql stmt valid is.
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: ../index.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($pwd, $row['pwdUsers']);
if ($pwdCheck == false) {
header("location: ../index.php?error=wrongpwd");
exit();
}
elseif($pwdCheck == true){
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userEmail'] = $row['emailUsers'];
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();
}
代码在我的本地主机上运行良好。但是在我的网站服务器上,它无法正常工作。这段代码运行的代码刚刚停止。您不会发送到下一页。
我认为它卡在这部分的某个地方:
$result = mysqli_stmt_get_result($stmt);
奇怪的是我的注册码运行正常。因此,我可以创建一个新用户,并将信息发送到数据库即可。但是登录脚本根本不起作用。但是这两个脚本真的很相似。
谢谢您的帮助!