简体   繁体   English

Facebook API的require_login与CodeIgniter一起使用

[英]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. 当前,如果我使用Facebook的require_login,它似乎会陷入无限附加到url的循环中。 All of my controllers inherit from a FB_Controller that upon construction does: 我所有的控制器都继承自FB_Controller,该FB_Controller在构造时会执行以下操作:

$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. 我必须在Facebook上将画布回调URL显式设置为http://decider.dfgh.org/ask/index/ (其中ask是我想要的默认控制器),否则会出现404错误。 Also I'm using the iframe rendering method. 另外,我正在使用iframe渲染方法。

On CodeIgniter I have the typical mod_rewrite to get rid of index.php, $config['uri_protocol'] = "REQUEST_URI", $config['enable_query_strings'] = TRUE. 在CodeIgniter上,我有典型的mod_rewrite来摆脱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). 我必须设置后两个配置才能使简单的链接正常工作(单击诸如http://decider.dfgh.org/decide/之类的链接将不起作用,它只会导航至当前页面)。

I just set the uri_protocol to either request_url or path_info depending on the referrer header. 我只是根据引用标头将uri_protocol设置为request_url或path_info。 So in config.php I have: 所以在config.php中,我有:

$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'; / * Facebook Connect黑客* / if(isset($ _ SERVER ['HTTP_REFERER'])&& strpos($ _ SERVER ['HTTP_REFERER'],'facebook.com')!== false){$ config ['uri_protocol'] = 'PATH_INFO'; } else { $config['uri_protocol'] = 'REQUEST_URI'; } else {$ config ['uri_protocol'] ='REQUEST_URI'; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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