执行top.location.href后丢失php发布的字符串变量信息


Losing php posted string variable information after executing top.location.href

以下代码涉及使用php表单事件触发的脚本对Facebook应用程序用户进行身份验证。我通过HTML表单发布了一个字符串,代码如下:

<html>
<body>
<form name="form" enctype="multipart/form-data" action="test.php" method="post">
    <input name="message" type="text" value=""><br/><br/>
    <input type="submit" value="Upload"/><br/>
</form>
</body>
</html>

test.php的代码是:

<html>
    <head xmlns:testapp="https://apps.facebook.com/testapp/ns#">
        <title>World Centric</title>
    </head>
    <body>
    <?php
    $app_id = "191622610935428";
    $my_url = "http://www.thepropagator.com/facebook/testapp";
    $string1 = $_POST["message"];
    session_start();
    $_SESSION['string']=$string1;
    echo $string1;
    $code = $_REQUEST["code"];
    if(empty($code)) 
    {
        $dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
            . $app_id . "&redirect_uri=" . urlencode($my_url) 
            . "&scope=email,publish_actions";
        echo("<script>top.location.href='" . $dialog_url . "'</script>");
        echo "string1".$string1;
    }
   $string1 = $_SESSION['string'];
    echo $string1;
    ?>
    </body>
</html>

当text.php最初执行is echos时,从表单发布的字符串

$string1 = $_POST["message"];

然而,在线路之后:

echo("<script>top.location.href='" . $dialog_url . "'</script>");

执行时,变量$string1为空。我需要在执行上述行之后保留此信息。有人能建议我如何做到这一点吗?

当您像在Javascript中那样更改href时,它会导致通过"GET"加载新的URL。如果需要保留这样的变量,则必须将它们传递到新url的查询字符串中,或者将它们存储在其他位置,例如cookie或服务器端会话中。