我正在使用facebook-php-sdk和我的codeigniter应用程序。 当我试图从我的URL中删除index.php时,我的身份验证有问题。
我对facebook connect的实现很简单,工作正常。 (sdk核心文件是一个库,带有app数据的cofig文件)当我输入时,身份验证效果很好:
myapp.com/index.php/welcome
但是在我尝试的时候:
myapp.com/welcome
我可以单击并单击并单击登录 - 页面只刷新。
我的欢迎控制器:
public function __construct()
{
parent::__construct();
// Your own constructor code
$CI = & get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
$this->load->library('facebook', $config);
}
public function index()
{
echo CI_VERSION;
$user = $this->facebook->getUser();
if($user) {
$user_info = $this->facebook->api('/me');
echo '<pre>'.htmlspecialchars(print_r($user_info, true)).'</pre>';
} else {
echo "<a href=\"{$this->facebook->getLoginUrl()}\">Login using Facebook</a>";
}
}
简单:经过身份验证后,它只会打印我的fb帐户数据。
我的.htaccess:
RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
RewriteRule ^index\.php/?(.*) /$1 [R,L]
RewriteCond $0 !^index\.php($|/)
RewriteRule .* index.php/$0 [L]
更新
我的登录网址来自mysite.com/welcome 不工作
https://www.facebook.com/dialog/oauth?client_id=487********73&redirect_uri=http%3A%2F%2Fmysite.com%2Fwelcome&state=ae51191b8eabf884ead0c116e7e28b4d
来自mysite.com/index.php/welcome 工作精细
https://www.facebook.com/dialog/oauth?client_id=487********73&redirect_uri=http%3A%2F%2Fmysite.com%2Findex.php%2Fwelcome&state=ae51191b8eabf884ead0c116e7e28b4d
答案 0 :(得分:2)
你可以尝试使用不同的.htaccess吗?我已经在FB的一些CI项目中使用了这个,没有遇到麻烦:
<IfModule mod_rewrite.c>
RewriteEngine On
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
考虑一下froddd的说法,ig您的默认控制器是受欢迎的,那么您只需使用www.yoursite.com或www.yoursite.com/welcome