带有CodeIgniter的Facebook PHP-SDK没有返回$_REQUEST [‘signed_request’]

class Example extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {

        $this->load->library('facebooklib');

        $user = $this->facebooklib->getUser();

        if ($user) {
            try {
                $data['user_profile'] = $this->facebooklib->api('/me');
            } catch (FacebookApiException $e) {
                $user = null;
            }
        }

        var_dump($_REQUEST);

        if ($user) {
            $data['logout_url'] = $this->facebooklib->getLogoutUrl();
        } else {
            $data['login_url'] = $this->facebooklib->getLoginUrl();
        }

        $this->load->view('view',$data);
    }
}

点击登录链接后,我被带到Facebook权限页面,我接受了,并且我返回到没有数据的同一页面.

array(3) {
  ["/example"]=>
  string(0) ""
  ["PHPSESSID"]=>
  string(32) "33a446883d4fb1877fb6dcff6d70799a"
  ["ci_session"]=>
  string(311) "a:4:{s:10:"session_id";s:32:"d8bb3926550e3ec1b9d075b456708e9b";s:10:"ip_address";s:9:"127.0.0.1";s:10:"user_agent";s:120:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19";s:13:"last_activity";i:1336011855;}c874fb95984396f04ab6cc17217102d7"
}

我的$_REQUEST转储并没有真正显示signed_request,这是一个问题.

最佳答案
尽管有所有的downvotes,我能够找到解决这个非常严重的BUG在Facebook PHP-SDK与CodeIgniter发现.

所以这里是CI论坛中找到的解决方案:http://codeigniter.com/forums/viewthread/202370/#986781

    // Stop cache
    $this->ci->output->set_header("Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    $this->ci->output->set_header("Pragma: no-cache");

    // IE Fix
    if(strpos($this->ci->agent->agent_string(), 'MSIE') !== FALSE) {
        $this->ci->output->set_header('p3p: CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"');
    }

    // Repopulate _REQUEST ... Facebook needs it.
    $request_uri = $_SERVER['REQUEST_URI'];
    $request_uri = explode('?',$request_uri);
    if(count($request_uri) > 1) {
        parse_str($request_uri[1], $_REQUEST);
    }

出于某种原因,新的PHP SDK不会通过CodeIgniter传递$_REQUEST.缓存也存在问题,IE没有正确的标头.

所以这从$_SERVER [‘REQUEST_URI’]构建$_REQUEST,然后正确地通过Facebook类并成功返回正确的数据.

转载注明原文:带有CodeIgniter的Facebook PHP-SDK没有返回$_REQUEST [‘signed_request’] - 代码日志