开发者

Browser incompatibility problem

开发者 https://www.devze.com 2023-03-31 19:00 出处:网络
The code bellow works well with latest version of Chrome on Linux and Windows, latest version of Firefox in Linux and Windows, all IE versions on Windows except IE9.

The code bellow works well with latest version of Chrome on Linux and Windows, latest version of Firefox in Linux and Windows, all IE versions on Windows except IE9.

Unfortunately, it does not work as expected with IE9 in Windows and latest version of Chrome and Firefox on MacOS

I did a couple of test and I found that the error happens when redirecting from the Facebook application's canvas page to another Facebook canvas application that uses an IFrame to show the first application. When redirection happens $user is null on the above mentioned browser on MacOS and IE on Windows but it is not null and working as expected for every browser mentioned in first paragraph.

Any suggestion?

<?php    
$user            =   null; //facebook user uid
try{
    include_once "src/facebook.php";
    include_once "src/fb_logger.php";
}
catch(Exception $o){
    echo '<pre>';
    print_r($o);
    echo '</pre>';
}
// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
));

//Facebook Authentication part
$user       = $fac开发者_JAVA百科ebook->getUser();

// We may or may not have this data based 
// on whether the user is logged in.
// If we have a $user id here, it means we know 
// the user is logged into
// Facebook, but we dont know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

$loginUrl   = $facebook->getLoginUrl(
        array(
            'scope'         => 'user_status,publish_stream,user_photos'
        )
);

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

            if(isset($_GET['iframe']) || isset($_GET['code']))) {
    }
    else {
    echo "<script type='text/javascript'>
        if(window.location.href.toLowerCase().indexOf('iframe') != -1 || window.location.href.toLowerCase().indexOf('oauth') != -1 || window.location.href.toLowerCase().indexOf('code') != -1) {
        }
        else
                            //opening new application with iframe to show the previous one
            window.open('link to the iframe pointing to the this application', '_parent', '');
        </script>";
        exit;
    }
  } catch (FacebookApiException $e) {
    //you should use error_log($e); instead of printing the info on browser
    //d($e);  // d is a debug function defined at the end of this file
    $user = null;
  }
}

if (!$user) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}
?>


I think I found the solution

I added:

//required for IE in iframe FB environments if sessions are to work.
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

in my code and it's now working.

0

精彩评论

暂无评论...
验证码 换一张
取 消