dpcj40970 2012-05-03 02:28
浏览 50
已采纳

带有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);
    }
}

After clicking on the Login link, I am taken to Facebook permissions page, I accept, and I am returned to the same page with no data.

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"
}

My $_REQUEST dump doesn't really show signed_request, which is a problem.

  • 写回答

3条回答 默认 最新

  • doushi6864 2012-05-03 06:56
    关注

    Despite all the downvotes, I was able to find the solution to this VERY serious BUG found in Facebook PHP-SDK with CodeIgniter.

    So here's the solution found in CI forums: 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);
        }
    

    For some reason, the new PHP SDK doesn't pass $_REQUEST through CodeIgniter. There's also issues with cache, and IE not having proper header.

    So this builds $_REQUEST from $_SERVER['REQUEST_URI'], which then properly passes through Facebook class and successfully returns proper data.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度