PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
FernandoBasso
Forum Newbie
Posts: 13 Joined: Sun Dec 05, 2010 4:05 am
Location: Brazil
Post
by FernandoBasso » Wed Jan 16, 2013 5:25 pm
I have this very basic piece of code, for the welcome, I see the url parameter, but
not for the login failed, which redirects the user back to /login/. Why?
Code: Select all
if (mysqli_num_rows($result_set) == 1) {
$found_user = mysqli_fetch_array($result_set);
$_SESSION['user_logged'] = TRUE;
$_SESSION['name'] = $found_user['name'];
$_SESSION['success_msg'] = 'Olá, ' . $found_user['name'] . '!';
/* The parameter is always there. */
header('Location: ../welcome/?login=true');
}
else {
$_SESSION['error_msg'] = 'Dados inválidos.';
/* No parameters in the url here. Why? */
header('Location: ../login/?login=false');
}
Last edited by
FernandoBasso on Thu Jan 17, 2013 3:10 am, edited 1 time in total.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Wed Jan 16, 2013 5:27 pm
Do you have other code which tries to redirect to just /login/?
You should be exit;ing immediately after you send those header()s.
Code: Select all
if (mysqli_num_rows($result_set) == 1) {
$found_user = mysqli_fetch_array($result_set);
$_SESSION['user_logged'] = TRUE;
$_SESSION['name'] = $found_user['name'];
$_SESSION['success_msg'] = 'Olá, ' . $found_user['name'] . '!';
/* The parameter is always there. */
header('Location: ../welcome/?login=true');
exit;
}
else {
$_SESSION['error_msg'] = 'Dados inválidos.';
/* No parameters in the url here. Why? */
header('Location: ../login/?login=false');
exit;
}
FernandoBasso
Forum Newbie
Posts: 13 Joined: Sun Dec 05, 2010 4:05 am
Location: Brazil
Post
by FernandoBasso » Wed Jan 16, 2013 7:02 pm
Yep, I had some other stuff that was also redirecting to /login/. Tnanks for calling it to my attention.
Also updated the code o use exit() after the redirects.
Thanks a lot.