du1108 2013-11-26 16:54
浏览 55
已采纳

php标头位置重定向方法无法正常工作

    <?php
    if(isset($_SESSION['logged_in']))
    {
            header('Location: test.php');
echo "test";
    ?>

    <?php
    }
    else
    {
    ?>
            <a href="#" onclick="CallAfterLogin();"><img src="facebook-login-button.png" border="0" alt="Log in with Facebook"></a>

    <?php } ?>

After the user is login, I visit back to this file, and it just won't redirect. It did appear the echo but not the redirect, I wonder.

  • 写回答

2条回答 默认 最新

  • dream752614590 2013-11-26 16:59
    关注

    try this

        <?php
        ob_start();
            if(isset($_SESSION['logged_in']))
            {
                    header('Location: test.php');
        echo "test";
            ?>
    
            <?php
            }
            else
            {
            ?>
                    <a href="#" onclick="CallAfterLogin();"><img src="facebook-login-button.png" border="0" alt="Log in with Facebook"></a>
    
            <?php }
    ob_end_flush();
     ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?