I don't succeed to change the location (URL) with the "header('Location: URL');"
I've a form in a modal, I submit with Jquery $.post method for create a new user, in the controller before creating the User from POST data, I check if the mail or the name is free. So I've made a simple if-else control with some location for showing an error from the URL GET. On the paper, it was simple and even if not optimized, must working fine, no need more work for this project.
expected:
If user exist:
reload with user error in the URL;
elseif mail exist:
reload with mail error in the URL;
else:
createNewUser(data);
Real code:
if(User::userExist($userName)){
header('Location: index.php?action=users&error=userAlreadyExist');
die();
}
I want to reload page/url with new data error for display it to the user.
Atm the post is okay(data received, the ifelse control is okay), but the code dont relocate with the header.
I've tried without Jquery and pass it with a normal post/submit, but it's the same problem.
In these 2 cases, I've a "magic" behavior. When I change the location, with for example: header('Location: index.php?action=loginFail');
The page doesn't relocate, but if I refresh (F5) the page, she going on this location. It's not the case with wanted URL, so just the question, why?
I can modify the global behavior for making it working. But take times for no real gain on this project (It's a basic student project with just php requirement, that part is already more than what is expected)
But I really want to understand why the header dont work here?
Not sure if all is clear... I'll try to explain at my best but I'm a little confused.