API Facebook не позволяет вам выпускать заголовки перенаправления для страницы аутентификации. Вот страница аутентификации, которую я использую, с частями, относящимися только к моей странице. Если вы введете этот код, он будет работать, так как я использую его в своей работе для своего приложения на Facebook. Он также реализует защиту от CSRF.
РЕДАКТИРОВАТЬ : Я удалил APP_SECRET, потому что я сомневаюсь, что вам это нужно.
<?php
$valid = false;
define(APP_ID, "");
define(CHROMED_URL, "");//this is the facebook app url in the form http://apps.facebook.com/[app name]
$desired_perms = "";//place the permisions you want here
$auth_url = "https://www.facebook.com/dialog/oauth?client_id=".APP_ID."&redirect_uri=".urlencode(CHROMED_URL)."&scope=".$desired_perms;
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if ( empty($data["user_id"])) {
//The user is not logged in, or the user has not authorized the app
//We start a session to maintain a marker variable for XSS attack detection
//The auth url will log the user in AND acquire permissions if needed.
$_SESSION['marker'] = md5(uniqid(rand(), TRUE)); //CSRF protection
session_write_close();
echo("<script> top.location.href='".$auth_url."&marker=".$_SESSION['marker']."'</script>");
} else {
if ($_SESSION['marker'] == $_GET['marker']) {
//The user is logged in, has given the app permission, and appears to be operating under the correct session
//marker, which protects against XSS attacks.
//lets verify the datas algorithm as a precaution
if ($data["algorithm"] != "HMAC-SHA256") {
echo("<script> top.location.href='./error.php?id=1'</script>");
exit;
}
$valid = true;
} else {
//This branch means the user is logged in, but that it appears they have been subjected to
//an XSS attack.
echo("<script> top.location.href='./error.php?id=2'</script>");
exit;
}
}
?>
<?php if($valid): ?>
<!-- PUT The HTML to embed your application here -->
<?php endif; ?>