Facebook Safari Session Problem – Safari Iframe Set Cookie
If you’re struggling with a session_start or cookie in safari you may already know that Apple decided to enforce the cookie policy and fix some security issues that allowed us to add cookies from third party websites – for instance iframes such as Facebook Apps & Page tabs.
I have created a workaround for this, since basically all you need to do is load your page on top.location, create the session and redirect it back to facebook.
Add this code in the top of your index.php and set $page_url to your application final tab/app URL and you’ll see your application will work without any problem.
-
<?php
-
// Start Session Fix
-
$page_url = "http://www.facebook.com/pages/…/…?sk=app_…";
-
{
-
$_SESSION["signed_request"] = $_POST["signed_request"];
-
}
-
// End Session Fix
-
?>


Thanks for the solution. It works nice
Thanks for the solution, it’s solves the problem with Safari but it seems to kill the session since my POST calls stop working after implementing this. Any idea why?
Hello @Ricardo,
Just updated the code snipped, you just need to add any $_REQUEST/$_POST/$_GET variables (such as signed_request, as shown above) to session and use them (the session variables) instead.
Thank you and sorry for the late reply!
You just save my life.
Thanks!
This is just throwing me into an infinite loop of redirects. Does this code need to be on every page, like in the config file, or just on the index page?
Nevermind – I just fixed it. It did need to go in the config/all pages, not just the index page.
THANK you for such an easy and awesome workaround to the 3rd party cookie issue!!
You’re welcome
!
Sorry for not seeing your comment sooner.
It should work only on the index page (being the index page your facebook application/tab landing page).
Anything let me know.