I'm currently working on a small php project to teach me PHP, javascript, etc.
I've got a index.php, which is supposed to manage which site is being accessed. I use _GET variables to do so.
If the login_message isn't set, login.php will be opened. (This works just fine.) A few textboxes and a button are generated for the user input.
After the login has been processed, index.php will be called again and the login_message will be set.
After that the user should be redirected to input.php (if the login was successful and the correct input_message has been send) where he can input some other data.
The problem: input.php will be processed (if using the header()
function), but the page won't refresh itself.
What I tried:
header("Refresh:0 Location:input.php");
echo '<script type="text/javascript">';
echo 'window.location.replace("http://someurl/input.php")';
echo '</script>';
echo '<script type="text/javascript">';
echo 'window.location.assign("http://someurl/input.php")';
echo '</script>';
echo '<script type="text/javascript">';
echo 'window.location.href("http://someurl/input.php")';
echo '</script>';
I'm guessing header()
won't work because the HTML code has already been generated in login.php? index.php is completely free of whitespace or HTML code.
Use die(header("Location:input.php"));
without any javascript. Please notice the die
or exit
.
You have your login form. The user enters credentials and submits them. You get the credentials and proceed them. You decide to either redirect or show the login form again. Between getting the credentials and redirecting there is no html code necessary. Sending a header after html code does not work.