Reputation: 135
I coded a registration form and after every input has been validated , it sends some data to the database and redirects to the login page.
I want to display a message on the login page tho like : Registration Successful - Login Here
if (!validated() {
// post error messages
} else {
echo '
<div class="container">
<div class="page-header">
<h3>Registration Complete</h3>
</div>
</div>';
header( 'Location: ../login.php' );
}
Login file :
Header - Navbar
<div class="container">
<div class="page-header">
<h3>Login To Members Corner</h3>
</div>
<form>
// login form
</form>
Footer
Upvotes: 0
Views: 22049
Reputation: 21694
You can't redirect to a file after output has been shown. You have two alternate solutions here:
Refresh the page after a timeout while showing the message in the meantime, using a <meta>
tag:
<meta http-equiv="refresh" content="5; url=../login.php">
Output the message after redirection:
<?php
header('Location: ../login.php?registered=true');
And in login.php:
<?php
if (@$_GET['registered'] == 'true')
echo 'You have registered successfully.'
Upvotes: 2
Reputation: 49929
You do a header("Location")
to redirect the page. That is possible but than you want to add a paremeter where you can detect if the registration was successful. Something like:
header( 'Location: ../login.php?action=success' );
And than in you file do this:
if( $_GET['action'] == 'success' ) {
echo "thanks for you registration, log in here";
}
Because if you redirect, the current request vars will not be available in the redirected page. So you need to pass them on to the next.
Upvotes: 2