这是我在本地计算机上的 XAMMP 服务器上创建的基本登录脚本。在本地服务器上工作得很好。将其上传到我的 windows deluxe go daddy 托管服务,但它不再有效。该脚本正确地提取用户输入的用户名和密码并正确验证它。但是,似乎 $_SESSION 变量被设置为空。但是我知道它用来设置变量的数组不是空的,因为它实际上是使用相同的数组来验证登录凭据。目前,当您登录时,您会在代码中设置的 url 栏中收到成功消息,并在您应该正确收到错误时,因此验证不是问题。我还仔细检查了会话确实已经开始,但是它似乎没有更新。我的标题中还有 session_start() 方法,它作为一个独立的脚本包含在我的所有页面中,包含在页面顶部。我已经尝试删除它并让登录脚本成为启动该会话的唯一代码,它没有任何区别。但是,如果我在标头本身中包含会话变量的设置,它就可以正常工作。所以不知何故会话变量被设置为空。有任何想法吗?
Edit2:您可以访问 selfscales.com 查看实际中的错误
<?php
session_start();
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 inputs are empty
if(empty($uid) || empty($pwd)){
header("Location: ../index.php?login=empty");
exit();
} else {
$sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck < 1) {
header("Location: ../index.php?login=error");
exit();
} else {
if($row = mysqli_fetch_assoc($result)){
//deashing the password
$hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
if($hashedPwdCheck == false){
header("Location: ../index.php?login=error");
exit();
} elseif ($hashedPwdCheck == true) {
//login 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'];
header("Location: ../index.php?login=success");
exit();
}
}
}
}
}
else {
header("Location: ../index.php?login=error");
exit();
}
编辑1:索引页面
<?php
include_once 'header.php';
include 'includes/ssdb.inc.php';
?>
<link rel="stylesheet" href="testingPHP/stylesheets/w3.css">
<section class="main-container">
<div class="main-wrapper">
<?php
if(isset($_SESSION['u_id'])){
echo '<h2>Weigh</h2>';
} else{
echo '<h2>Welcome To Selfscale!</h2>';
echo '<h4>Selfscale is a web application that eliminates the need
for a scalehouse.</h4>';
echo '<h4>Selfscale allows truck drivers to purchase a weigh
without the need to talk to anyone.</h4>';
echo '<h4>Please sign in or login.</h4>';
echo '<h4> Notice: First time users will need to register their
company, truck and trailer.</h4>';
echo '<h4>Then purchase a weigh for a small fee.</h4>';
echo '<h4>You will have the option to download your weigh ticket,
email it to yourself, or print it out the old fashion way.</h4>';
include 'weighForm.php';
}
?>
<?php
if(isset($_SESSION['u_id'])){
}
?>
</div>
</section>
<?php
include_once 'footer.php';
?>