我想在我的網站上使用Facebook創建一個登錄。我在互聯網上發現了一個代碼,使它簡單地加載了Facebook的PHP sdk庫。我嘗試了代碼,但它在我身上不起作用。請幫助我如何在facebook上使用codeigniter進行登錄。Facebook的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 -->
,也沒有任何錯誤,當我在檢查我的控制檯,我不知道發生了什麼,我是添加庫的初學者。請幫我解決一下這個。由於
hello sir,..謝謝你的回答。我會在哪裏放置我的appsecret和appid?我已經加載我的網址幫手自動加載 –
'var $ ci;''將其轉換爲'公共$ ci'; –
先生,我已經改變了onclick =「<?php回聲base_url('user_authentication');?>」但它也是一樣的地方沒有任何反應,它只刷新/重新加入我的網頁每次我點擊按鈕 –