Hi I’m beginner in Codeigniter.
I have 4 view page that have facebook login (1. login page 2.register page 3.login special member page 4.register special member page)
And all 4 views file I have to initial facebook php sdk like this
<?php require_once(APPPATH.'libraries/facebook/src/facebook.php');
$facebook = new Facebook(array(
'appId' => '201637766943985',
'secret' => '4e70dc1dbfc4787e81bec0d7b57d6a1c',
));
$user = $facebook->getUser();
It’s very annoying that one day I have to change appID and appsecret, I have to change it in 4 view files.
so I create new view file name “fb_init.php” that contain code
<?php require_once(APPPATH.'libraries/facebook/src/facebook.php');
$facebook = new Facebook(array(
'appId' => '201637766943985',
'secret' => '4e70dc1dbfc4787e81bec0d7b57d6a1c',
));
$user = $facebook->getUser();
and then in 4 view files I include fb_init.php by write
$this->load->view('fb_init.php');
However, The problem is the remaining code of facebook php sdk cannot refer to $user
variable.
the remaining code of facebook sdk is here.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me?fields=id,email,name,first_name,last_name,picture'); //ต้องมีหลัง /me ไม่งั้นประวัติมาไม่ครบ
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$loginUrl = $facebook->getLoginUrl(array(
"redirect_uri"=>"http://www.club55.net/login",
"scope"=>"email"
));
How could I do?
2
Answers
Try this, in your
fb_init.php
.And in your view file.
you can do it using javascript it will open facbook login popup on our site will not redirect to facebook site.
please follow this —
It`s a universal code we can use this code in any languages or in any technology, hope it will work.