0

我将 facebook-php-sdk 与我的 codeigniter 应用程序一起使用。当我试图从我的 URL 中删除 index.php 时,我遇到了身份验证问题。

我对 facebook connect 的实现很简单并且工作正常。(sdk 核心文件是一个库,以及带有应用程序数据的 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
4

1 回答 1

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 所说的,如果您的默认控制器是受欢迎的,那么您可以只使用 www.yoursite.com 或 www.yoursite.com/welcome

于 2012-10-01T22:28:12.587 回答