Tuesday, August 20, 2013

How to set P3P headers in Codeigniter?

What is P3P header?
The Platform for Privacy Preferences Project (P3P) is a protocol allowing websites to declare their intended use of information they collect about web browser users. Designed to give users more control of their personal information when browsing, P3P was developed by the World Wide Web Consortium (W3C) and officially recommended on April 16, 2002.

If you didn't set P3P header, it may not work properly in IE browsers.

Real world problem and solution example
Problem: My codeigniter application is trying to set cookies from inside an iFrame, and this is not working very well with IE8.
Solution: Add P3P headers

IE's "high" privacy setting blocks all cookies from websites that do not have a compact privacy policy, but cookies accompanied by P3P non-policies like those below are not blocked.

In order to set the P3P header in Codeigniter, place following code within the index.php page, like so:

header('P3P:CP="We do not have a P3P policy!"');

// ... rest of the index.php file 
The only place I have found this worked in codeigniter :)

Note: It didn't worked using Codeigniter output class ( $this->output->set_header )

No comments:

Post a Comment