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

2008 March 27

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 leave one →
  1. 2008 April 4
    Double permalink

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

  2. 2008 May 8
    Adam permalink

    A thousand thank you’s :-)

  3. 2008 May 28
    Konrad Maquestieau permalink

    Thank you. Thank you. Thank you.

  4. 2008 June 5
    kaichi permalink

    thanks for this very helpful article…

  5. 2008 June 22
    nikul permalink

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

  6. 2008 June 23

    Thanks a ton Nikul for appreciating ;) :)

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

  7. 2008 June 25
    Eric permalink

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

  8. 2008 June 25

    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.

  9. 2008 June 26
    Asad Mohiuddin permalink

    Thanks!!! Alot.
    Really very helpful

  10. 2008 July 1
    Eric permalink

    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

  11. 2008 November 3
    Eduardo permalink

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

  12. 2009 February 18

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

  13. 2009 March 19
    Reno permalink

    Thanks a lot! that helped alot!

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS