0

我已經有一段時間了Facebook開發人員,但我剛剛開始使用新的Facebook應用程序佈局,並且堅持了第一步。顯然,我的舊認證方法不再適用。無法在IE中進行身份驗證

爲了解決這個問題,我嘗試了一個例子http://developers.facebook.com/docs/authentication/。但是,它在Internet Explorer上似乎並不起作用。

這裏是我的代碼下方:

<?php 
$app_id = "-----"; 
$app_secret = "------"; 
$my_url = "http://apps.facebook.com/myapp/"; 
require('facebook-php-sdk-2343fca/src/facebook.php'); 
$facebook = new Facebook(array(
          'appId' => $app_id, 
          'secret' => $app_secret, 
          'cookie' => true,)); 
$session = $facebook->getSession(); 
session_start(); 
$code = $_REQUEST["code"]; 
echo $_REQUEST['state']." == ".$_SESSION['state']; 

if(empty($code)) { 
    $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection 
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
     . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="  
     . $_SESSION['state'] . '&scope=publish_stream,read_stream,user_photos,friends_photos,user_events,friends_events'; 
    echo("<script> top.location.href='" . $dialog_url . "'</script>"); 
} 

if($_REQUEST['state'] == $_SESSION['state']) { 
    $token_url = "https://graph.facebook.com/oauth/access_token?" 
    . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) 
    . "&client_secret=" . $app_secret . "&code=" . $code; 

    $response = file_get_contents($token_url); 
    $params = null; 
    parse_str($response, $params); 

    $graph_url = "https://graph.facebook.com/me?access_token=" 
     . $params['access_token']; 

    $user = json_decode(file_get_contents($graph_url)); 
    //echo("Hello " . $user->name); 

//My app goes here! 
    } else { 
    echo("The state does not match. You may be a victim of CSRF."); 
} 
?> 

到目前爲止,我所知道的是這個問題與$_SESSION['state']做;

任何幫助將非常有義務!

回答

1

嗯,我得到它的工作。用Internet Explorer和iframe處理P3P cookie是一個相當模糊的問題。總之,只要把這個地方在你的代碼的開頭:

 
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); 

你可以在這裏閱讀更多:How to properly handle session and access token with Facebook PHP SDK 3.0?

+0

應該這樣做,謝謝! –

相關問題