使用Facebook的Codeigniter登录没有任何反应 [英] Codeigniter login with facebook nothing happens

查看:99
本文介绍了使用Facebook的Codeigniter登录没有任何反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上使用Facebook创建登录名。我在互联网上找到了一个代码,可以轻松地加载Facebook php sdk库。我尝试了该代码,但对我无效。请帮助我如何在codeigniter中使用Facebook登录。

I want to create a login with Facebook in my website. I found a code in the internet that made it simple loading the library of Facebook php sdk. I tried the code but it doesn't work in me. Please help me how to do login with facebook in codeigniter.

以下是代码:

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

require_once( APPPATH . 'libraries/facebook/src/facebook.php' );

class FacebookApp extends Facebook {

var $ci;

var $facebook;

var $scope;

public function __construct() {
  $this->ci =& get_instance();

  $this->facebook = new Facebook(array('appId'  => $this->ci->config->item('app_id'),'secret' => $this->ci->config->item('app_secret'), 'cookie' => true));

$this->scope = 'public_profile';
}

public function login_url() {
  $params = array('scope' => $this->scope);
  return $this->facebook->getLoginUrl($params);
}

public function logout_url() {
  return $this->facebook->getLogoutUrl(array('next' => base_url() .'logout'));
}

public function getFbObj(){
  return $this->facebook;
}

public function get_user() {
  $data = array();
  $data['fb_user'] = $this->facebook->getUser();
  if ($data['fb_user']) {
    try {
      $data['fb_user_profile'] = $this->facebook->api('/me');
      return $data;
    } catch (FacebookApiException $e) {
      $this->facebook->destroySession();
      $fb_login_url = $this->facebook->getLoginUrl(array('scope' => $this->scope));
      redirect($fb_login_url, 'refresh'); 
    }
  }
}

这是我的控制器:

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class User_Authentication extends CI_Controller
{
    function __construct() {
        parent::__construct();
        // Load user model
        $this->load->model('auth/user_model');
        $this->load->library('facebook/FacebookApp');
    }

    public function index(){
        $obj_fb = new FacebookApp();
        $fb_user_data = $obj_fb->get_user();
        $data['fb_login_url'] = $obj_fb->login_url();
    }
}

这是我的观点:

<div class="modal fade" id="choose" role="dialog">
  <div class="modal-dialog"> 
    <div class="modal-content">
      <div class="modal-header  btn-success">
               <h3 class="modal-title">Connect with</h3>
      </div><!-- modal-header -->
        <div class="modal-body">
          <div class="connectwith">
          <form class="form-horizontal" id="payment">
              <button onclick="<?php echo base_url()?>User_authentication" class="btn btn-primary"> Continue with Facebook </button>
          </form><!-- form-horizontal -->
          </div>
        </div><!-- modal-body -->
    </div><!-- modal-content -->
  </div><!-- modal-dialog -->
</div><!-- choose -->

当我在控制台上检查它时,它没有显示错误,我不知道发生了什么,我是添加库的初学者。请帮我解决一下这个。谢谢

it shows no error when i check it on my console, i don't know what's happen, i am a beginner in adding libraries. Please help me with this. Thanks

推荐答案

使用此github https://github.com/bhawnam193/php-programs/tree/master/facebook-login 用于使用fb登录。
首先制作一个Facebook应用并替换

Use this github https://github.com/bhawnam193/php-programs/tree/master/facebook-login for using fb login . Firstly make a facebook app and replace the

$app_id ,$app_secret, $site_url 

在文件 fbaccess.php 中。

这篇关于使用Facebook的Codeigniter登录没有任何反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆