Daniel Boy Marpaung
Daniel Boy Marpaung

Reputation: 33

Why my page redirection does't work?

I don't know what's wrong with my code. I'm trying to make a simple page redirection. But it doesn't work. If i visit login.php page, then i click login, it will stay in login_process.php and show nothing, that it should redirect to books.php. And if i have logged in and i visit login.php again, it will ask the username and password, but it should not happened

//Login.php

    <?php

        include_once ('autoload.php');

        open_page($configs['web_name']);
    ?>

    <form action="login_process.php" method="post">
        <table border="1">
            <tr>
                <td>Username</td>
                <td>:</td>
                <td><input type="text" name="username"></td>
            </tr>

            <tr>
                <td>Password</td>
                <td>:</td>
                <td><input type="password" name="password"></td>
            </tr>
            <tr>
                <td colspan="3"><input type="submit" name="action" value="login"></td>
            </tr>
        </table>
    </form>

    <?php
    close_page();
    ?>

//Login_process.php

    <?php

        include_once ('autoload.php');

        $is_logged_in = get_session('is_logged_in');
        if(!$is_logged_in){
            $username = get_form_post('username');
            $password = get_form_post('password');

            if($configs['username'] == $username && $configs['password'] == $password){
                set_session('is_logged_in',TRUE);
            }else{
                redirect('login.php');
            }
        }
            redirect($configs['main_page']);

And the redirect function is :

function redirect($_location){
        header('Location : ' .$_location);
    }

Upvotes: 0

Views: 43

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74220

Remove the space in:

header('Location : ' .$_location);
                ^ space

so that it reads as:

header('Location: ' .$_location);

There should not be a space between Location and the colon :

Upvotes: 1

Related Questions