-1

(This does not answer my question).

I am trying to redirect to the landing page after a user attempts to login, here is what I've done:

<?php
ob_start();
session_start();
if ($loginSuccess)
{
    echo "Logged in: True";
    header("Location: index.php?status=1", true, 200);
}
else
{
    echo "Logged in: False";
    header("Location: index.php?status=0", true, 401);
}
ob_end_flush();
exit();
?>

However when I try this I get the page never gets redirected back to the page that the request was made with (index.php)

enter image description here

Josie
  • 79
  • 8
  • 1
    A `Location` header _alone_ does not redirect, it needs to be accompanied by a 3xx status code. But what do we have here, according to your screenshot? `Status: 401` – 04FS Sep 23 '20 at 07:11
  • Wow, so that was the problem? It worked with 308, thank you for the answer! – Josie Sep 23 '20 at 15:27

1 Answers1

-1

try put this code before the ob_start(), becuase the header sometimes already called

ob_clean()

or change to javascript redirect using this if the ob_clean() not worked

echo "<script>window.location.href='index.php?status=1'</script>";
ilham suryoko
  • 55
  • 1
  • 1
  • 9
  • Didn't work and I do not want to use JavaScript in my situation as I'm returning a JSON object in my actual code. – Josie Sep 23 '20 at 03:11