コードを実行するには、おそらくセミコロンが必要です。また、等号が必要です。(デビッド・バーカーに感謝)
$app_id = APP_ID;
$canvas_page = APP_LINK;
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,read_stream";
echo "<script> top.location.href='" . $auth_url . "';</script>";
これを行うと何が得られますか: echo "<script> alert('".$auth_url."');</script>";
?
また、PHPでこれを行う簡単な方法は次のとおりです。
$app_id = APP_ID;
$canvas_page = APP_LINK;
$auth_url = "http://www.facebook.com/dialog/oauth?client_id". $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,read_stream";
echo <<<EOT
<script>
top.location.href="$auth_url";
//checking the value of auth_url to see if that is the reason redirect is not happening.
if (window.console) {
console.log("$auth_url");
} else {
alert("$auth_url");
}
</script>
EOT;
ヒアドキュメント構文を使用すると、何もエスケープする必要がなくなり、単一引用符と二重引用符を使用でき、変数は文字列内で本質的に置き換えられます。;)