这个程序已有 4 年历史,但我正在努力让它发挥作用。 https://github.com/msaad1999/KLiK-SocialMediaWebsite 我按照所有说明进行操作,一切似乎都正常,但在单击登录按钮后,我在 Apache 2 中收到以下错误。我也确实在两个文件夹中添加了一个 .htacces 文件。
::1 - - [21/Apr/2023:15:55:30 -0500] "POST /socialmedia/includes/login.inc.php HTTP/1.1" 302 354 "https://sourcecodedepot.com/socialmedia/ login.php" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.0.0"
在研究 302 是某种不起作用的重定向之后,标头确实显示 login=success 但它没有重定向。如果您查看注释掉的代码,我试图将其重定向到我的主页,但没有成功。我是 php 和 html 的新手 1 有 2 个问题 1 我不确定 ../ 是什么意思 我假设它进入下一个文件夹? 2 我怎样才能让重定向回到默认页面不知道默认页面应该是什么。这是错误日志中引用的代码
<?php
if (isset($_POST['login-submit']))
{
require 'dbh.inc.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password))
{
header("Location: ../login.php?error=emptyfields");
exit();
}
else
{
$sql = "SELECT * FROM users WHERE uidUsers=?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql))
{
header("Location: ../login.php?error=sqlerror");
exit();
}
else
{
mysqli_stmt_bind_param($stmt, "s", $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: ../login.php?error=wrongpwd");
exit();
}
else if($pwdCheck == true)
{
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
$_SESSION['userLevel'] = $row['userLevel'];
$_SESSION['emailUsers'] = $row['emailUsers'];
$_SESSION['f_name'] = $row['f_name'];
$_SESSION['l_name'] = $row['l_name'];
$_SESSION['gender'] = $row['gender'];
$_SESSION['headline'] = $row['headline'];
$_SESSION['bio'] = $row['bio'];
$_SESSION['userImg'] = $row['userImg'];
//$_SESSION['coverImg'] = $row['coverImg'];
header("Location: ../index.php?login=success");
//header("Location: ../sourcecodedepot.com/socialmedia/index.php");
exit();
}
else
{
header("Location: ../login.php?error=wrongpwd");
exit();
}
}
else
{
header("Location: ../login.php?error=nouser");
exit();
}
}
}
}
else
{
header("Location: ../login.php");
exit();
}