Eternal reloading page with Internet Explorer

前端 未结 2 1608
盖世英雄少女心
盖世英雄少女心 2021-01-15 19:33

I\'ve got a problem with my FB apps with Internet Explorer 7.

I\'m using this piece of code, provided by FB some time ago :

$auth_url = \"http://www.         


        
相关标签:
2条回答
  • 2021-01-15 20:14

    https://gist.github.com/2765933 has a solution in Sinatra/Ruby that helped me with this issue!

    I found it to be the p3p issue, I just wanted to post some sample code for anyone who finds this after me.

    0 讨论(0)
  • 2021-01-15 20:22

    Couldn't get you code to work either, it just reloaded. Seems $_REQUEST["signed_request"] was never set.

    But I got it to work with the code from http://developers.facebook.com/docs/authentication/

       <?php
       $app_id = "your app id";
       $app_secret = "your app secret";
       $my_url = "your app url";
    
       session_start();
       $code = $_REQUEST["code"];
    
       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'];
    
         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);
       }
       else {
         echo("The state does not match. You may be a victim of CSRF.");
       }
    

    That said, I would recommend you to use the Facebook PHP SDK, http://developers.facebook.com/docs/reference/php/ that makes programming facebook apps easier.

    EDIT: using the PHP SDK

    To authenticate with the PHP SDK, you would do something like the following:

    // update this to where you've stored the facebook PHP SDK
    require '../src/facebook.php';
    
    $facebook = new Facebook(array(
      'appId'  => 'your app id',
      'secret' => 'your app secret',
    ));
    
    $user = $facebook->getUser();
    if ($user) {
      print "You've logged in!";
    } else {
      echo("<script> top.location.href='" . $facebook->getLoginUrl() . "'</script>");
    }
    

    EDIT: headers

    Also, try setting this in the first lines of you code:

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

    This helped me when the fb session was lost sometimes in an app. Found that in this post: How to properly handle session and access token with Facebook PHP SDK 3.0?

    0 讨论(0)
提交回复
热议问题