Safari 会话变量中具有多个页面的 Facebook Iframe 应用程序不持久

发布于 2024-08-29 20:24:23 字数 240 浏览 7 评论 0原文

我有一个 facebook Iframe 应用程序,其中包含多个 PHP 页面。

我有一些链接相对于我的“iframe 文件夹”内的文件。

iframe 内的会话变量存在一些问题。我设置了一些会话变量,但它们不会从一个页面持续到另一个页面。

这确实适用于其他浏览器。

我一直在读到 Safari 不支持跨域 cookie,这可能是问题所在,但我不知道如何解决这个问题。

有什么帮助吗?

I have a facebook Iframe application with multiple PHP pages in it.

I have some links that point relatively to the files inside my "iframe folder".

Having some issues with session variables inside the iframe. I set some session variables but they do not persist from one page to another.

This does work on other browsers.

I've been reading that Safari does not support Cross-Domain cookies and this might be the problem , but im not sure how to fix this.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

十秒萌定你 2024-09-05 20:24:23

我相信这个解决方案对于最新版本的 Safari(6.0 及更高版本)来说已经过时了。

默认情况下,Safari 不允许第三方设置 cookie。这会影响 Facebook iframe 应用程序,因为用户正在访问由 apps.facebook.com 提供的页面,但 iframe 是由 yourdomain.com 提供的,即“第三方”这个案例。

网络上提到了几种解决方案。我发现的最好的一个,也是 Facebook 在其杂项问题列表中推荐的一个< /a> 是使用 JQuery 向 yourdomain.com 伪造 POST 请求。 Anant Garg 详细介绍的此解决方案通常适用于不同的主机/iframe 域,需要针对 Facebook 应用程序进行调整。关键部分是:

$("body").append('
 <iframe id="sessionframe" name="sessionframe" onload="submitSessionForm()" src="http://www.yourdomain.com/blank.php" style="display:none;"></iframe>
 <form id="sessionform" enctype="application/x-www-form-urlencoded" 
   action="http://www.yourdomain.com/startsession.php"
   target="sessionframe" method="post"></form>');
var firstTimeSession = 0;
function submitSessionForm() {
  if (firstTimeSession == 0) {
    firstTimeSession = 1;
    $("#sessionform").submit();
  }
}

Will Henderson 将使用 Javascript 函数使用会话信息来检测页面上的每个链接。然后修改您的服务器代码以通过从 GET 参数读取该会话信息来捕获该信息。

I believe this solution has become obsolete with the latest (6.0 and later) versions of Safari.

Safari by default does not allow cookies to be set from third parties. This affects Facebook iframe applications because the user is accessing a page served from apps.facebook.com but the iframe is being served from yourdomain.com, the "third party" in this case.

There are several several solutions mentioned around the web. The best I've found and one recommended by Facebook in its list of miscellaneous issues is to fake a POST request to yourdomain.com using JQuery. This solution detailed by Anant Garg works in general for different host/iframe domains and needs to be adapted for Facebook apps. The key parts are:

$("body").append('
 <iframe id="sessionframe" name="sessionframe" onload="submitSessionForm()" src="http://www.yourdomain.com/blank.php" style="display:none;"></iframe>
 <form id="sessionform" enctype="application/x-www-form-urlencoded" 
   action="http://www.yourdomain.com/startsession.php"
   target="sessionframe" method="post"></form>');
var firstTimeSession = 0;
function submitSessionForm() {
  if (firstTimeSession == 0) {
    firstTimeSession = 1;
    $("#sessionform").submit();
  }
}

Another solution by Will Henderson is to instrument each link on your page with session information using a Javascript function. Then modify your server code to capture this session information by reading it from GET parameters.

撩动你心 2024-09-05 20:24:23

我写了博客文章 多米尼克在他的回答中提到。

问题在于 Safari 的默认行为是仅接受您访问的网站的 cookie。这不包括“第三方”cookie。 Safari 将 IFRAME 内的页面视为第三方网站,并且在您与该内容交互(例如通过单击链接)之前,它将拒绝这些 cookie。

您的 PHP 代码需要在使用会话的第一页上设置一个 cookie,以便该会话从一个页面持续到另一个页面,但如果会话变量位于 IFRAME 的第一页中,那么您就遇到了麻烦-鸡蛋问题。

我的解决方案是保留所有特殊的 Facebook 参数,直到加载到 IFRAME 中的第二个页面。因为您已经与它进行了交互,所以第二页上设置的 cookie 将持续存在,这允许您的 PHP 代码保持与 Facebook 通信所需的任何状态。

不过,这不太可能对您的 PHP 会话有帮助,因此我建议向第一页上的链接添加另一个参数,以允许第二页查找会话,或者以其他方式重新创建它。

I wrote the blog post Dominic refers to in his answer.

The problem is that the default behavior of Safari is to only accept cookies from sites that you visit. This excludes "third party" cookies. Safari treats the page inside an IFRAME as a third-party site, and until you interact with that content (by clicking a link, for example), it will refuse those cookies.

Your PHP code needs to set a cookie on the first page that uses the session in order for that session to persist from one page to another, but if the session variables are in the very first page in the IFRAME, you have a chicken-and-egg problem.

My solution is to retain all of the special Facebook parameters through to the second page loaded into the IFRAME. Because you've interacted with it, cookies set on the second page will persist, and this allows your PHP code to keep whatever state it needs to communicate back to Facebook.

This won't likely help your PHP session, though, so I suggest adding another parameter to links on the first page that allows the second page to look the session up, or otherwise recreate it.

瑶笙 2024-09-05 20:24:23

我认为最好的解决方案是手动跟踪会话 ID,即使用 session_id($_GET['session]); 只需确保在调用 session_start();< 之前执行此操作即可/code> 一切正常。

I think the best solution is to manually keep track of the session ID i.e. by using session_id($_GET['session]); Just make sure you do this before calling session_start(); and everything works.

负佳期 2024-09-05 20:24:23

Safari 仅接受用户导航到的页面中的 cookie。解决此问题的最简单、最有效的方法是使用 top.location.href 将请求从画布应用的登录页面重定向到域中的其他页面,并将用户重定向回画布应用从该页面。

例如,如果 abc.php 是您的登陆页面,而画布 URL 是 facebook.com/abc。首先将请求从 abc.php 重定向到不同的页面,例如 xyz.php,然后再次从 xyz.php 重定向到 facebook.com/abc。不要忘记在 xyz.php 中启动会话。

这是简单的修复...

Safari accepts cookies only from the page the user navigates to. The easiest and most effective way to fix this is to redirect the request from landing page of your canvas app to a different page on your domain using top.location.href and redirect the user back to the canvas app from that page.

For example, if abc.php is your landing page and the canvas URL is facebook.com/abc. First redirect the request from abc.php to a different page like xyz.php then redirect again from xyz.php to facebook.com/abc. Don't forget to start the session in xyz.php.

This is the simple fix...

冰火雁神 2024-09-05 20:24:23

并感谢您的所有投入。我最终通过在每个页面上附加“signed_request”参数来解决问题。我只是将其作为隐藏字段并将其设置在后面的代码中。这样我就可以让它在 Safari 中工作了。希望它也适合你。

and thanks for all the input. I ended up solving the problem by appending the "signed_request" paramter on every page. I just put it in as a hidden field and set it in the code behind. That way I managed to get it to work in Safari. Hope it works for you too.

走过海棠暮 2024-09-05 20:24:23

随着 Safari 7 的发布,不仅第 3 方 cookie 被阻止。本地存储以及WebDB,任何类型的网站数据都被阻止。当您进入 Safari 首选项(CMD+逗号)时,在 Safari 7 上的隐私选项卡下,它现在显示:“阻止 cookie 和其他网站”,最初是“阻止 cookie”。这证实了这些变化。

其他浏览器将来可能会跟进。最有可能的是火狐。 Chrome,咳嗽*咳嗽*可能不会。

您可能必须采用一些解决方法,使用重定向技术或弹出窗口,类似于 disqus 所做的。

With the release of Safari 7, not only 3rd Party cookie is being blocked. Local Storage as well as WebDB, any kind of website data are being blocked. When you go to Safari Preferences (CMD+comma), Under privacy tab, on Safari 7, it now says : "Block cookies and other website", originally was "Block cookies". That confirms the changes.

Other browsers might follow through in the future. Most probably Firefox. Chrome, cough *cough* probably not.

You probably have to employ some workaround using redirection technique or popup similar to what disqus did.

冷情 2024-09-05 20:24:23

如果您使用 .NET,那么这个问题有一个更简单的解决方案。

只需在 web.config 中将 cookieless 设置为 false 即可。例如:

sessionState mode="InProc" cookieless="true" timeout="60" 

它比发布 iframe 或使用 iframe 的 url 打开弹出窗口要容易得多。

亲切的问候,

大卫

If you using .NET then there is a much simpler solution to this problem.

Just set cookieless to false in your web.config. Ex:

sessionState mode="InProc" cookieless="true" timeout="60" 

Its a lot easier than posting an iframe, or opening a popup window with the url of the iframe.

kind regards,

David

看春风乍起 2024-09-05 20:24:23

我在 PHP 中使用了这个标头,它解决了我的问题

if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

I used this header with PHP, that fix my problems

if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文