Page 1 of 1

(SOLVED) header Location, parameters

Posted: Wed Jan 16, 2013 5:25 pm
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');
        }


Re: header Location, parameters

Posted: Wed Jan 16, 2013 5:27 pm
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;
        }

Re: header Location, parameters

Posted: Wed Jan 16, 2013 7:02 pm
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.