I had a (very) simple login script which was working beautifully, and somehow, without much, if any, changes on the script page I have the following error:
The Problem
<meta http-equiv="refresh" content="0; url=http://www.xxxxxx.com/index.php" />
The above code is not refreshing, which means the user is not getting redirected after login. He/she has to manually refresh the page to start his/her session:
As you can see from above image, the login was successful, but the page isn’t refreshing.
Please note using header("location:")
is not an option here:
Also note I’m using Ajax with the form submission for what that is worth…
Part of the login script:
if ($_SERVER["REQUEST_METHOD"] == "POST") { // Do stuff if(mysqli_num_rows($result) = 1) { while { // GET session variables }//while echo 'Success! Logging In....'; echo '<meta http-equiv="refresh" content="0; url=http://www.xxxxx.com/index.php" />'//now refresh page } //if } //if
Strangely, this was working for me above, but it has since yesterday stopped working.
Solution
Is there a reason why this is not working?
Is there anything I can do to fix this?
Is there any alternative approach?
Advertisement
Answer
The way you are trying to do it will not work, because the <meta>
tag is supposed to come in the <head>
section of your page, not in the body. Plus, you can’t use <meta http-equiv="refresh">
or any other header directives once output is sent.
Try replacing this part:
echo '<meta http-equiv="refresh" content="0; url=http://www.xxxxx.com/index.php" />'
with this:
echo '<script>location.href="http://www.xxxxx.com/index.php"</script>';