How To Fix PHP Sessions Data Issue In Internet Explorer & In IFRAMES?


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 70% 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, before session_start() function:

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.

Hope it helps you too!

About SachinKRaj

Sachin is a web application developer, technology blogger and web addict! He has over 6 years of web development experience and he writes tutorials primarily focused on LAMP, Ajax, Api's, jQuery etc. He is usability expert and he always likes to share his knowledge with people.

, , , ,

4 Responses to How To Fix PHP Sessions Data Issue In Internet Explorer & In IFRAMES?

  1. Rich Hessler Solar April 14, 2010 at 6:26 pm #

    I am being tortured by IE right now. PHP works great in Safari and FF, but the SESS is deleted in IE everytime I close the window.

  2. Ozy245 September 2, 2010 at 2:46 am #

    Thank youu

  3. Felipe January 9, 2011 at 9:13 am #

    Thanks a lot !

  4. Mohamed Arafat September 27, 2011 at 2:43 pm #

    Still doesn't work… Seriously… I'm F**** hate the F***ing IE…

    STUPID IE Programmers… (the as** Ho**s in microsoft)

    When the world goes in one way Microsoft goes the other FU***ing way…..

    They are a pain in the ass…

Leave a Reply