Facebook php sdk getUser(); return 0 value on IE

Having a stupid bug in our “Dearest” IE! When I am building a facebook app using iframe within facebook environment

The problem is when you using Facebook PHP SDK,

Sytnax was as below:
[code type=php]
require_once("php-sdk/facebook.php");

$config = array(
'appId' =>"Your ID'',
'secret' => 'Your Secret',
'cookie' => false, // enable optional cookie support

$facebook = new Facebook($config);
$user = $facebook->getUser();
[/code]
When you check on getUser() it returns 0 values, however, it does not appear in other browser than IE.
Why it is happening?  After 4hours of research, I found a solution to it and the cause.

For my case was PHP. Add this to all the pages inside your Iframe.
[code type=html]
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); // This is the main cause to use on IE.
require 'php-sdk/facebook.php';

$facebook = new Facebook(array(
'appId' =>"Your ID'',
'secret' => 'Your Secret',
));

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
echo '

'.htmlspecialchars(print_r($e, true)).'

';
$user = null;
}
}?>
[/code]
I tried it out and it looked like everything worked great in Safari and Firefox but not IE. It is a session
problem, the session ID was not being passed in IE. The problem lies with a W3C standard called
Platform for Privacy Preferences or P3P for short. This will allow Internet Explorer to accept your third-party cookie.
You will need to send the header on every page that sets a cookie.

Solution on PHP:
[code type=php]
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
[/code]

Solution on JSP:


[code type=jsp]response.setHeader("P3P","CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'")
[/code]

Solution on cold fusion
[code type=html][/code]

However, I only did test on PHP and it works fine!



Leave a Reply

You must be logged in to post a comment.