(SOLVED) header Location, parameters

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

Post Reply
User avatar
FernandoBasso
Forum Newbie
Posts: 13
Joined: Sun Dec 05, 2010 4:05 am
Location: Brazil

(SOLVED) header Location, parameters

Post by FernandoBasso »

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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: header Location, parameters

Post by requinix »

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;
        }
User avatar
FernandoBasso
Forum Newbie
Posts: 13
Joined: Sun Dec 05, 2010 4:05 am
Location: Brazil

Re: header Location, parameters

Post by FernandoBasso »

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.
Post Reply