提交登录表单后,我无法让我的页面重定向。我在这里看到了其他的Q& A页面,看起来我根据他们的建议正确地做了但我不知道为什么它不起作用。
我在XXAMP上测试了它并且在那里工作得很好,但是一旦我将它上传到我的网站就停止了工作(该页面没有重定向回index.php。
我正在登录,我可以确保这一点,因为一旦我登录并被发送到空白页面,我可以转到地址栏并再次输入网站名称,它会显示我已登录英寸
我很感激任何帮助!
谢谢!
这是我的index.php页面:
<!--This is my index.php page-->
<?php
include 'includes/header.php';
?>
<div class = "container">
<div class = "container-fluid">
</div>
<?php
if (isset($_SESSION['uid'])) {
echo "<div class = 'loggedin'>
<p>You are logged in as " . $_SESSION['uid'] . ".</p>";
echo "<div class = 'date'>Today is ";
$dayofweek = date("w");
//echo $dayofweek;
switch ($dayofweek) {
case 1:
echo "Monday";
break;
case 2:
echo "Tuesday";
break;
case 3:
echo "Wednesday";
break;
case 4:
echo "Thursday";
break;
case 5:
echo "Friday";
break;
case 6:
echo "Saturday";
break;
case 0:
echo "Sunday";
break;
}
$fulldate = date(", F jS, Y.");
echo $fulldate .
"</div></div>" .
"<p>Welcome, " .
$_SESSION['fname'].
"!</p>" .
"<div class = 'profilephoto'></div>";
}
else {
echo "<div class = 'main'>
<p>Sign up below to start using this free site!</p>
</div>
<div class = 'signinform'><form action = 'includes/login.php' method = 'POST'>
<label for = 'uid'>Username: </label>
<input type = 'text' name = 'uid' placeholder = 'Username'>
<br>
<label for = 'pwd'>Password: </label>
<input type = 'password' name = 'pwd' placeholder = 'Password'>
<br>
<button type = 'submit'>Sign In</button>
</form>
<div class = 'joinnowbutton'><p>Not a member? <a href = 'joinnowpage.php'>Join Now</a></p></div></div>";
}
?>
</div>
</div>
这是我的login.php页面:
<!--This is my login.php page-->
<?php
session_start();
include '../dbh.php';
?>
<?php
$inputuser = mysqli_real_escape_string($conn, $_POST['uid']);
$inputpass = mysqli_real_escape_string($conn, $_POST['pwd']);
if (empty($inputuser) || (empty($inputpass))) {
echo "Invalid username or password.";
die();
}
$sql = "SELECT * FROM users WHERE uid = '$inputuser' AND pwd = '$inputpass'";
$result = $conn->query($sql);
if ($row = mysqli_fetch_assoc($result)){
$_SESSION['uid'] = $row['uid'];
$_SESSION['fname'] = $row['fname'];
$_SESSION['lname'] = $row['lname'];
$_SESSION['city'] = $row['city'];
$_SESSION['state'] = $row['state'];
$_SESSION['uid'] = $row['uid'];
header("Location:../index.php");
}
else {
header("Location:/fail.php");
}
$conn->close();
?>