以下代码涉及使用由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最初执行时,回显从表单
发布的字符串$string1 = $_POST["message"];
然而在行之后:
echo("<script>top.location.href='" . $dialog_url . "'</script>");
执行变量$ string1为空。执行上面的代码后,我需要保留这些信息。可以建议我如何实现这个目标吗?
答案 0 :(得分:1)
当您在Javascript中更改href时,会导致通过“GET”加载新URL。如果你需要保存这样的变量,你必须在新的url的查询字符串中传递它们,或者将它们存储在别处,例如在cookie或服务器端会话中。