This is a step by step tutorial for Codeigniter users for using the Facebook connect feature in their websites. For the users who generates Codeigniter websites using PHP Code Generator" (PCG) the Facebook connect library for CodeIgniter library is already included in the library folder in the downloaded website.s
<?php
$config['appId'] = 'Your Facebook App ID';
$config['secret'] = 'Your Facebook secret key';
?>
<?php
include(APPPATH.'libraries/facebook/facebook.php');
class Fb_connect extends Facebook
{
//declare public variables public
$user = NULL;
public $user_id = FALSE;
public $fb = FALSE;
public $fbSession = FALSE;
public $appkey = 0;
//constructor method.
public function __construct()
{
$CI = &get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser(); // New code
$me = null;
if ($this->user_id)
{
try
{
$me = $this->api('/me');
$this->user = $me;
}
catch (FacebookApiException $e)
{
error_log($e);
}
}
}
}
// end class
function loginByFacebook()
{
$this->load->library('fb_connect');
$param['redirect_uri']=site_url("user/facebook");
redirect($this->fb_connect->getLoginUrl($param));
}
function facebook()
{
$this->load->library('fb_connect');
if (!$this->fb_connect->user_id)
{
//Handle not logged in,
}
else
{
$fb_uid = $this->fb_connect->user_id;
$fb_usr = $this->fb_connect->user;
//Handle user logged in,by updating session
//print_r($fb_usr) will help to see what is returned
}
}
By now you should have a working implementation of Facebook connect. If you have difficulties implementing the Facebook connect in CodeIgniter website, we recommend to use PHP Code Generator where you get a working implementation with role based authentication and admin portal etc.
This is a step by step tutorial for Codeigniter users for using the Facebook connect feature in their websites. For the users who generates Codeigniter websites using PHP Code Generator" (PCG) the Facebook connect library for CodeIgniter library is already included in the library folder in the downloaded website.s
<?php
$config['appId'] = 'Your Facebook App ID';
$config['secret'] = 'Your Facebook secret key';
?>
<?php
include(APPPATH.'libraries/facebook/facebook.php');
class Fb_connect extends Facebook
{
//declare public variables public
$user = NULL;
public $user_id = FALSE;
public $fb = FALSE;
public $fbSession = FALSE;
public $appkey = 0;
//constructor method.
public function __construct()
{
$CI = &get_instance();
$CI->config->load("facebook",TRUE);
$config = $CI->config->item('facebook');
parent::__construct($config);
$this->user_id = $this->getUser(); // New code
$me = null;
if ($this->user_id)
{
try
{
$me = $this->api('/me');
$this->user = $me;
}
catch (FacebookApiException $e)
{
error_log($e);
}
}
}
}
// end class
function loginByFacebook()
{
$this->load->library('fb_connect');
$param['redirect_uri']=site_url("user/facebook");
redirect($this->fb_connect->getLoginUrl($param));
}
function facebook()
{
$this->load->library('fb_connect');
if (!$this->fb_connect->user_id)
{
//Handle not logged in,
}
else
{
$fb_uid = $this->fb_connect->user_id;
$fb_usr = $this->fb_connect->user;
//Handle user logged in,by updating session
//print_r($fb_usr) will help to see what is returned
}
}
By now you should have a working implementation of Facebook connect. If you have difficulties implementing the Facebook connect in CodeIgniter website, we recommend to use PHP Code Generator where you get a working implementation with role based authentication and admin portal etc.
Do you know that you can generate a complete PHP websites in minutes with PHP Website Generator?