为什么我的FB应用程序在IE中永远循环? [英] Why my FB app loops forever in IE?

查看:157
本文介绍了为什么我的FB应用程序在IE中永远循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Facebook应用程序,在IE中运行时会永远循环。在其他浏览器中,它的工作正常。

I have a Facebook app which loops forever when run in IE. In other browsers it works fine.

我需要你的帮助来调试这个,但在此之前,我需要提及我如何实现它。

I need your help to debug this, but before that I need to mention how I have implemented it.

FB建议当用户尝试访问应用程序时,我们应该将用户重定向到应用程序授权页面。从那里FB将重定向(使用302代码)到我们喜欢的网址。在这种情况下,我要求FB在查询字符串中使用标记 appLogin = 1 重定向到我的应用程序的URL。但是随着FB在查询字符串中附加了一个非常难看的参数代码。所以在这种情况下,我在PHP会话中添加了一个标记 LoggedIn ,并使用JS代码 window.top将用户重定向到应用程序的URL。 location.href =< app url> 。这可以清除位置栏中的URL。

FB recommends that when user tries to access the app we should redirect the user to the app authorization page. From there FB will redirect (using 302 code) to an url which we like. In this case I ask FB to redirect to my app's url with a flag appLogin=1 in query string. But along with that FB attaches a really long param code in the query string which is quite ugly. So, in this case I put a flag LoggedIn in my PHP session and redirect the user back to the app url using a JS code window.top.location.href = <app url>. This cleans the url in the location bar.

这在Firefox和Chrome中工作正常,但在IE LoggedIn 标志代码从 appLogin 阶段重定向后,会话中缺少。在这种情况下,PHP会话似乎已经重置了。这使我的应用程序误认为这是一个初始请求,所以它将用户重定向到授权页面。

This works fine in Firefox and Chrome, but in IE LoggedIn flag is missing from the session after the code redirects from appLogin stage. In fact it seems the PHP session has reset in this case. This confuses my app into believing that this is an initial request so it redirects user to the authorization page.

我希望以上是有道理的。真的很感激任何见解。

I hope the above makes sense. Really appreciate any insight.

Update1:​​

根据要求。这里是代码片段。

As requested. Here goes the code snippet.

$reset = false;
$topRedirect = true;

if (isset($_REQUEST['appLogin'])) {
    resetSession();
}
session_start();

$facebook = new Facebook(array(
  'appId' => $AppId,
  'secret' => $AppSecret,
  'cookie' => true,
));

if (isset($_REQUEST['appLogin'])) {//Comes here when appLogin is set, i.e. we have just been redirected here from OAuth (authorization) page.

    if (isset($_REQUEST['error'])) {
        if ($_REQUEST['error_reason'] === 'user_denied') {
            $msg = "You need to click on 'Allow', so that this App can fetch the data needed.";
            $allowRetry = true;
            include('error.php');
        }
    }

    $authToken = $facebook->getUserAccessToken(); //This was originally protected. Made public for my purpose.
    if ($authToken === false) {
        //If no user token found and it wasn't even an error then this is totally unexpected.
        $msg = "Totally unexpected error occurred!";
        $allowRetry = true;
        logErr($msg);
        include('error.php');
    }

    $_SESSION['LoggedIn'] = 1;
    $reset = false;
    $url = $AppUrl; //We redirect again to clean the url.
    include('redirect.php');
} else {
    if (!isset($_SESSION['LoggedIn']) || $facebook->getUserAccessToken() === false) {
        //If we are here then this is an initial request.
        $reset = false;
        $url = $OAuthUrl;
        include('redirect.php');
    }
}

$accessToken = $facebook->getAccessToken();

Update2:

包含的文件 - redirect.php和error.php在处理完成后调用 exit()。所以他们之后的代码不会被执行。

The included files - redirect.php and error.php invoke exit() when their processing is done. So the code after them won't get executed.

推荐答案

重定向是一个问题。 IE可以不同地处理它们。

It's a problem with redirects. IE handles them differently.

您可以使用简单的 P3P策略 HTTP头可以发送:

You can solve that with a simple P3P policy HTTP header you can send:

P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"

在PHP中,将是:

header('P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

原因是IE在使用框架时需要P3P策略,因为您的应用程序在iframe中运行并且其父属属于不同的域(本例为Facebook.com),则Cookie将不起作用(除非设置了P3P策略)。由于Cookie不起作用,那么您可能会循环使用用于登录Facebook的重定向。

The reason is that IE needs P3P policies in place when using frames, since your application runs inside an iframe and its parent belongs to a different domain (this case Facebook.com), then cookies will not work (unless P3P policies are being set). And since cookies won't work, then you are probably looping with your redirects used to login to Facebook.

解决方案:需要实现P3P头来告诉浏览器,iframe中的应用程序的cookie对用户的隐私是有效的。

这篇关于为什么我的FB应用程序在IE中永远循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆