如何在facebook之外禁用facebook iframe应用程序


How do i disable the facebook iframe app outside of facebook

我创建了一个iframe facebook应用程序,我想禁用facebook之外的应用程序,因为用户无法通过直接url打开该应用程序。我找到了一个使用javascript的解决方案,但我需要使用PHP。

我不能使用引用器,因为有些用户在浏览器中禁用了它。。。

您可以检查请求中是否发送了signed_request参数。若应用程序在facebook内部打开,则存在签名请求。

但还有一个问题
您应该检查signed_request是否有效,为此,您可以使用parse_signed.request方法

公共函数parse_signed_request($signed_rerequest,$secret){list($encoded_sig,$payload)=爆炸('.',$signed_request,2);

    // decode the data
    $sig = $this->base64_url_decode($encoded_sig);
    $data = json_decode($this->base64_url_decode($payload), true);
    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
        error_log('Unknown algorithm. Expected HMAC-SHA256');
        return null;
    }
    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
        error_log('Bad Signed JSON signature!');
        return null;
    }
    return $data;
}

然后您可以检查$data['user_id']是否存在,或者它是否等于已登录的用户。如果没有,你可以这样重定向
echo"<script type='text/javascript'>top.locationhref='$this->loginUrl';</script>";或者找到一些从php重定向的方法。(在旧的php-sdk中有重定向方法)

您唯一真正的选择是尝试以某种方式使用Facebook API,看看是否得到任何响应。