为什么我的页面重定向不起作用?

时间:2014-09-24 14:35:48

标签: php redirect

我不知道我的代码有什么问题。我正在尝试进行简单的页面重定向。但它不起作用。如果我访问login.php页面,然后我点击登录,它将保留在login_process.php并且不显示任何内容,它应该重定向到books.php。如果我已登录并再次访问login.php,它将询问用户名和密码,但不应该发生

// 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']);

重定向功能是:

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

1 个答案:

答案 0 :(得分:1)

删除以下位置:

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

所以它读作:

header('Location: ' .$_location);

Location与冒号:

之间不应有空格
相关问题