After successful registration, my user is redirected to the home page using:
echo
"<script type=\"text/javascript\">
window.location.href='../index.php';
</script>";
Do I need to follow this with
exit();
or is redirecting the user enough?
[EDIT] to help solve how to use die()/exit() alongside javascript in the same php file
jQuery:
$(document).ready(function() {
$("form").submit(function(event) {
event.preventDefault();
var username = $("#register-username").val();
var email = $("#register-email").val();
var password = $("#register-password").val();
var confirmPassword = $("#register-confirm-password").val();
var submit = $("#register-submit").val();
$(".form-message").load("../shared/_registerAccount.php", {
username: username,
email: email,
password: password,
confirmPassword: confirmPassword,
submit: submit
});
});
});
end of PHP script (success path):
else
{
$errorEmpty = $errorUsername = $errorEmail = $errorPassword = $errorConfirmPassword = false;
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($statement, "sss", $username, $email, $hashedPassword);
mysqli_stmt_execute($statement);
session_start();
$_SESSION['register-success'] = 'You have successfully registered! Please verify your email before logging in.';
$registrationSuccessful = true;
die('<script type="text/javascript">location.assign("../index.php")</script><a href="../index.php">Home</a>');
}
jQuery that follows PHP script in same file:
<script type="text/javascript">
var registrationSuccessful = "<?php echo $registrationSuccessful; ?>";
if (registrationSuccessful)
{
$("#register-username, #register-email, #register-password,
#register-confirm-password").val("");
}
</script>