SachinKRaj – The Blog

FIX PHP Sessions Data Issues in Internet Explorer and also make them workable for IFRAMES

Posted by: SachinKRaj on: March 27, 2008

Are you web developer? Oh yeah!!! then you must know how much you need to be aware such issues, like some of your web pages, web sites do not work on IE but runs perfectly on other popular browsers, i.e. Firefox, Safari.

Think about a day when you coded for something by spending lot of time on it, and it actually runs perfectly as you want on Firefox, Safari etc, but when you try to look same on Internet Explorer (IE), just one thing came into your mind, Oh goshhhhhh…. what went wrong with the code which leads to such issues. Your complete page reacts differently and all things got vanished and you just ask yourself, why??? The answer is that Microsoft’s IE takes everything differently as compared to other browsers. What a silly statement this is, Isn’t it? but its all true that even in the IE 7.0 version Microsoft has still not fixed all the issues those existed in IE 6.

JavaScript issues, CSS issues, Sessions data issues and lots of other issues are still there in IE or you can say a different approach followed in IE. It shouldn’t be like this, where world comes under a single web standard W3C and all browsers should be W3C compliant, so there should be common shared set of standards to develop browsers.

Still over 40% of world web users use IE. So from a developers point of view you cant avoid such issues which come under development phase; so you need a better approach to deal with them.

It renders pages differently, take care of data differently, when it comes to cookies and sessions. I faced a lot of problems regarding sessions in PHP in last week and got them fixed too. That is why I am writing this post to talk about the sessions and PHP issues with IE and how to fix it.

Now the actual issue, I was coding an script in PHP related to my recent project, it needs to run with IFRAME, means anyone can embed a piece of code to run my scripts which are directly linked to my server’s scripts. It includes the sessions data to store and pass to other scripts as well. When I runs it on Firefox or Safari, it runs well as expected but when I tried to run it on IE, I got nothing??? I was shocked. Is there anything I did wrong with my script? But I coded it well though…Then what goes wrong, which lead to such an issue? I searched a lot and at last found something about IE which again shocked me. In short the problem was, “IE blocks sessions data (cookies) when it comes from different domain”. When I was trying to run the script by direct typing URL on address bar it runs well on all browsers, but when I tried to run it with IFRAMES by embedding it to another site page, it failed on IE.

Actually IE privacy policy settings blocks the sessions data coming from the third party, the other domain. So you need to re-write the privacy policy P3P settings to override them and allow your script to store sessions data on IE based cookies.

To quick fix it, you need to write this line before anything to start in your PHP code file:

header(’P3P: CP=”NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM”‘);

Read this article http://www.oreillynet.com/mac/blog/2002/06/p3p_in_ie6_frustrating_failure.html to get all things clearly, I may not be well in explaining this but I can share it with you all. Do share your experience with IE.

13 Responses to "FIX PHP Sessions Data Issues in Internet Explorer and also make them workable for IFRAMES"

How did you get 3rd party session cookies working in an iframe in safari??? From what I have read, safari ignores p3p headers.

A thousand thank you’s :-)

Thank you. Thank you. Thank you.

thanks for this very helpful article…

Nth no. of thanks to you….
what a solution!!!!!!!!!!!!!!!

Thanks a ton Nikul for appreciating ;) :)

Come back for more great solutions.. ;) :)

I encountered the same problem and added the line to my code but it still wouldn’t work. please enlighten me. :)

Thanks for leaving comment on blog!

For your query on fixing IE sessions issue, could you provide me the code fragement where you are putting the code and also provide me the live running script example, so that I can help you.

Thanks!!! Alot.
Really very helpful

Hi!, im still researching about my problem and i found out that i still need to load mod_headers in my apache im still looking for other scripts and dependencies. i used a rpm installation for my apache and it sucks because its distributed across multiple directories and i still have to look for them one by one. as i have read so far i still need to configure my apache before i can begin to tackle my script/code. :) ill keep in touch

Great tip! This solve a big problem…
Thank you a lot!

Thank you very much for this article!
It helped us fix a long existing bug we never fixed before!

Thanks a lot! that helped alot!

Leave a Reply

Newsletter Subscription

Subscribe by Email

My Tweets

Fight Global Warming

Recent Visitors

BLOG Visitors

  • 483,592 hits