Facebook登录适用于localhost,但不适用于Web服务器 - Codeigniter

时间:2014-05-24 23:16:57

标签: php codeigniter facebook-login

所以,我尝试在本地主机上使用Codeigniter登录Facebook,一切都很好 - 当我按下登录按钮时,它显示了我的个人资料图片和注销按钮。

然后我在webhost上上传了脚本。我按下登录按钮,期待看到我的个人资料图片,但没有!除了一件事,网站ir,例如,www.example.com。我按登录和地址栏显示www.example.com/index.php?code=AQCTt5KzYV8TKKqU5nUUuy0d5DhQLJdFOlDgJ ...等。

我的welcome.php控制器代码:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Prakse extends CI_Controller {

public function __construct(){
    parent::__construct();

    // To use site_url and redirect on this controller.
    $this->load->helper(array('form', 'url'));
}

public function login() {

    $this->load->library('facebook');

    $user = $this->facebook->getUser();

    if ($user) {
        try {
            $data['user_profile'] = $this->facebook->api('/me');
        } catch (FacebookApiException $e) {
            $user = null;
        }
    }else {
        $this->facebook->destroySession();
    }

    if ($user) {

        $data['logout_url'] = site_url('welcome/logout'); // Logs off application
        // OR 
        // Logs off FB!
        // $data['logout_url'] = $this->facebook->getLogoutUrl();

    } else {
        $data['login_url'] = $this->facebook->getLoginUrl(array(
            'redirect_uri' => site_url('welcome/login'), 
            'scope' => array("email") // permissions here
        ));
    }
    $this->load->view('login',$data);

}

public function logout() {

    $this->load->library('facebook');

    // Logs off session from website
    $this->facebook->destroySession();
    // Make sure you destory website session as well.

    redirect('welcome/login');
}

}

请帮帮我。谢谢。

1 个答案:

答案 0 :(得分:0)

检查https://developers.facebook.com/apps/[your_app_id]/settings/并确保正确设置应用领域和网站网址。