X-Frame-Options禁止Facebook App错误

时间:2014-02-17 07:46:57

标签: php facebook facebook-php-sdk

我正在建立一个Facebook应用程序,目前它处于沙箱模式。我的代码: -

的index.php

<?php
ob_start();
@session_start();

require 'facebook.php';
include_once('config.php');


$facebook = new Facebook(array(
            'appId' => APP_ID,
            'secret' => SECRET_KEY,
            ));

$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }


    if (!empty($user_profile )) {
        # User info ok? Let's print it (Here we will be adding the login and registering routines)

        $username = $user_profile['name'];

        //echo '->'.$username;exit;
        $uid = $user_profile['id'];
        $email = $user_profile['email'];


        @session_start();
        //$_SESSION['id'] = $userdata['id'];
        $_SESSION['oauth_id'] = $uid;

        $_SESSION['username'] = $username;
        $_SESSION['email'] = $email;
        $_SESSION['oauth_provider'] = 'facebook';
        header("Location: home.php");

        ?>

        <?php


    } else {
        # For testing purposes, if there was an error, let's kill the script
        die("There was an error.");
    }
} else {
    # There's no active session, let's generate one
    $login_url = $facebook->getLoginUrl(array( 'scope' => 'email'));
    header("Location: " . $login_url);
}
?>

这里我正在检查用户是否登录,如果是登录用户然后重定向到主页,php则登录到facebook的登录页面。

但是当我在Facebook上运行我的应用程序时,它会在控制台上抛出错误: -

  

拒绝显示文档,因为X-Frame-Options禁止显示,因为它将'X-Frame-Options'设置为'DENY'

enter image description here

我也试过this解决方案,但它无法正常工作

2 个答案:

答案 0 :(得分:1)

您无法在任何类型的框架中显示登录对话框 - 这是一种反网络钓鱼措施,用户应该始终能够验证他们显示的登录对话框是否确实来自facebook.com,而不是从任何其他网站加载假货。

您必须在顶部窗口实例中重定向到它。这不能在服务器端完成,因此您必须使用JavaScript:

<script>top.location.href = "…";</script>

答案 1 :(得分:0)

而不是标题重定向使用JS重定向为

<script>top.location.href="THE URL"</script>