Facebook API's require_login to work with Code

2019-05-21 07:20发布

问题:

Currently if I use facebook's require_login, it appears to go into an infinite loop of appending to the url. All of my controllers inherit from a FB_Controller that upon construction does:

$this->facebook = new Facebook($this->API_KEY, $secret);
$this->uid = $this->facebook->require_login(); //Causes infinite loop!

I had to explicitly set the canvas callback URL on Facebook to http://decider.dfgh.org/ask/index/ (where ask is my desired default controller) or else I get a 404 error. Also I'm using the iframe rendering method.

On CodeIgniter I have the typical mod_rewrite to get rid of index.php, $config['uri_protocol'] = "REQUEST_URI", $config['enable_query_strings'] = TRUE. The latter two configurations I had to set to get simple linking to work (clicking on a link like http://decider.dfgh.org/decide/ would not work, it would just navigate to the current page).

回答1:

I just set the uri_protocol to either request_url or path_info depending on the referrer header. So in config.php I have:

$config['uri_protocol'] = 
    (isset($_SERVER['HTTP_REFERER']) && 
     strpos($_SERVER['HTTP_REFERER'], 'apps.facebook.com') !== false) ? 
         "PATH_INFO" : "REQUEST_URI";

Not the prettiest I admit but it works.



回答2:

I added this to my config file to do the exact same thing:

/* Facebook Connect hack */ if(isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'facebook.com') !== false) { $config['uri_protocol'] = 'PATH_INFO'; } else { $config['uri_protocol'] = 'REQUEST_URI'; }