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.

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();
 ?>

Judging by your code, it appears that you are trying to make this redirect happen in the middle of your page - you MUST do a redirect before any output has been made. Since this is right before an a tag I am assuming you already sent the <html> tag at some point, for example.

<?php //headers ok here ?>
<!DOCTYPE html>
<?php
  // Too late for headers already.