Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook / IE8 - Session is not being persisted

I have a Facebook iFrame application (written in PHP) and when I run it in IE8, my session data is not persisted.

I'm using Symfony 1.4 and have tried both Symfony's session wrapper and $_SESSION.

I set up two test pages: the first one defines $_SESSION['foo'] = 'bar' and calls print_r($_SESSION). The second page also calls print_r($_SESSION). I see my session variables set on the first page, but not on the second.

Everything works fine in Firefox and Chrome, and I've had two other people test this on different PCs running IE8 and they have the same problem.

I tried removing any Facebook javascript from my page thinking that it might somehow be interfering, but that didn't solve anything.

Any help would be greatly appreciated, thanks!

like image 539
Steven Mercatante Avatar asked Nov 06 '10 05:11

Steven Mercatante


2 Answers

After some more research, this is a specific problem with Facebook iframe apps and Internet Explorer. Luckily, the solution is very simple, I just needed to add this code header('P3P: CP="CAO PSA OUR"'); Everything works fine now!

Edit

After even more research, this problem isn't specific to Facebook, just iframes. It has to do with third party cookies and how Internet Explorer (and Safari) handle them. I want to note that the header code works for IE, but not Safari.

like image 104
Steven Mercatante Avatar answered Oct 21 '22 14:10

Steven Mercatante


I was having this same problem. PHP sessions were not persisting IE8, but they were in every other browser (Chrome, Firefox, Opera, Safari). Nothing worked. I tried everything from proper headers with P3P directives, cookie manipulation, resetting session id's, setting cookies to expire way in the future, blah, blah, blah.

Here is what finally worked (and I don't know why it works), but this was the culprit...

After days of debugging, I found that my script had an image tag that had a bad src reference in it, like this:

<img src="">

In other words, the src reference was empty/blank. THIS WAS THE CULPRIT TO MY WHOLE PROBLEM. I don't know why, but after putting in an actual image location like this:

<img src="./images/myimage.gif">

After correcting the empty src reference, everything worked fine and the PHP session was being set properly even in IE8. Believe or not, this was the reason behind the PHP session not being set.

I still have no idea but it worked fine after this. I'll have to research why this would cause a problem like this. If anyone knows why, please post the answer.

I hope this helps someone. :-)

like image 1
Eddie Avatar answered Oct 21 '22 12:10

Eddie