简体   繁体   中英

Facebook API's require_login to work with CodeIgniter

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).

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.

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'; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM