I can't get my page to redirect once the login form is submitted. I've seen other Q&A pages on here and it seems like I am doing it correctly according to their suggestions but I don't know why it's not working.
I tested it on XXAMP and it worked fine there, but once I uploaded it to my site it stopped working (the page does not redirect back to index.php.
I am getting logged in, and I can ensure this because once I log in and get sent to the blank page, I can go to the address bar and enter the site name again, and it will show me that I am logged in.
I'd appreciate any help!
Thanks!
This is my index.php page:
<!--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>
And this is my login.php page:
<!--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();
?>