Safari和php会话无法在facebook iframe中运行 [英] Safari and php sessions not working in facebook iframe
问题描述
我的问题是让我的Facebook应用在Safari上工作。
I'm having a problem to make my facebook app working on Safari.
这个问题与PHP会话变量有关。
The issue is related to the PHP session variables.
我知道Safari在处理跨域会话(在iframe内部)时遇到问题,我找到了大约2种类型的解决方案:
I am aware that Safari has a problem dealing with cross domain sessions (inside an iframe) and i found around 2 types of solutions:
- 设置p3p标头:我已经尝试了很多p3p标头,但没有一个工作[例如:
标头('P3P:CP =NOI ADM DEV COM NAV)我们的STP');
]。 - 使用javascript将帖子发送到iframe。这会创建交互,会话应该有效。但事实是我不控制iframe容器,因为那是facebook。
有没有人知道替代解决方案?
Does anyone know an alternative solution?
谢谢!
推荐答案
我迟到了,但可能会有所帮助别人正在查找这个问题。
I am late to this but it may well help someone else looking up this problem.
我能做的唯一方法就是从我的iframe中检测safari并在我可以设置会话cookie的时候重定向到另一个页面 - 然后重定向回来。
The only method I could make work was to detect safari from inside my iframe and redirect to another page momentarily where I could set my session cookie - then redirect back.
<?php
// sort out ie with the below header
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
session_start();
$_SESSION = array();
// if Safari and no cookies have been set yet, take me to another page to set a session cookie
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome')) {
if (count($_COOKIE) === 0) {
echo '<script>
top.location = "http://www.domain.com/setcookie.php";
</script>';
}
}
?>
然后来自setcookie.php
Then from setcookie.php
<?php
//inside setcookie.php
header('P3P: CP="CAO PSA OUR"');
session_start();
$_SESSION = array();
echo
'<script>
top.location = "http://www.backtooriginaldomain.com";
</script>';
?>
它有点蹩脚,但确实有效并且不会干扰其他浏览器。另一种方法是使用一个弹出窗口,虽然我的safari默认阻止它。
its a bit lame but does work and doesn't interfere with the other browsers. The other method is to use a popup window although my safari had this blocked by default.
这篇关于Safari和php会话无法在facebook iframe中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!