[英]Codeigniter login with facebook nothing happens
I want to create a login with Facebook in my website. 我想在我的网站上使用Facebook创建登录名。 I found a code in the internet that made it simple loading the library of Facebook php sdk.
我在互联网上找到了一个代码,可以轻松地加载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.
请帮助我如何在codeigniter中使用Facebook登录。
Here is the code : 这是代码:
<?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');
}
}
}
here is my controller : 这是我的控制器:
<?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();
}
}
and here is my view: 这是我的看法:
<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
谢谢
First of all load url
helper so you can use base_url()
.Load helper in controller... 首先加载
url
助手,因此您可以使用base_url()
在控制器中加载助手...
function __construct() {
parent::__construct();
//Load Helper
$this->load->helper('url');
// Load user model
$this->load->model('auth/user_model');
$this->load->library('facebook/FacebookApp');
}
In your view replace 您认为更换
onclick="<?php echo base_url()?>User_authentication"
To 至
onclick="<?php echo base_url('user_authentication');?>"
Use this github https://github.com/bhawnam193/php-programs/tree/master/facebook-login for using fb login . 使用此github https://github.com/bhawnam193/php-programs/tree/master/facebook-login来使用fb登录。 Firstly make a facebook app and replace the
首先制作一个Facebook应用并替换
$app_id ,$app_secret, $site_url
in file fbaccess.php . 在文件fbaccess.php中 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.