after success login using API facebook not redirect to right controller - freddy - 11-05-2015
Hi guys, quick questions
here is my code controller
Code: <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Register extends CI_Controller
{
public function index()
{
$data['login_url']= $this->facebook->getLoginUrl(array('redirect_uri' => site_url('register/loginfacebook'),
'scope' => array( "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
)));
$this->admin->load('template1', 'index', $data);
}
/*login facebook */
public function loginfacebook()
{
$user = "";
$userId = $this->facebook->getUser();
if ($userId) {
try {
$user = $this->facebook->api('/me?fields=id,name,link,email,gender');
} catch (FacebookApiException $e) {
$user = "";
}
}else {
$this->facebook->destroySession();
}
if($user!="")
{
$email = $user['email'];
$q = $this->db->select('email')->from('li_user')->where(array(
'email' => $email
))->get();
if ($q->num_rows() > 0) {
//update aja
$user_details = array(
'nama' => $user['name'],
'email' => $user['email'],
'user_status' => '1'
);
$this->session->set_userdata('user', $user);
$condition['email'] = $user['email'];
$this->model_register->updateuserbyfacebook($user_details,$condition);
// echo "you just update data";
}
else
{
$user_details = array(
'nama' => $user['name'],
'email' => $user['email'],
'user_status' => '1'
);
$this->session->set_userdata('user', $user);
$this->model_register->adduserbyfacebook($user_details);
// echo "you just insert data";
}
redirect(site_url('welcome')); //this redirect not giving me redirect
}
else
{
$data['login_url']= $this->facebook->getLoginUrl(array('redirect_uri' => site_url('register/loginfacebook'),
'scope' => array( "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
)));
$this->admin->load('template1', 'index', $data);
}
}
all works fine like charm but why after success login my controller doens't redirect the url stay,
i have tested in by echo with command works, but why my redirect doesn't redirect the page
Thanks for any words
Freddy Sidauruk
RE: after success login using API facebook not redirect to right controller - InsiteFX - 11-06-2015
(11-05-2015, 09:53 PM)freddy Wrote: Hi guys, quick questions
here is my code controller
Code: <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Register extends CI_Controller
{
public function index()
{
$data['login_url']= $this->facebook->getLoginUrl(array('redirect_uri' => site_url('register/loginfacebook'),
'scope' => array( "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
)));
$this->admin->load('template1', 'index', $data);
}
/*login facebook */
public function loginfacebook()
{
$user = "";
$userId = $this->facebook->getUser();
if ($userId) {
try {
$user = $this->facebook->api('/me?fields=id,name,link,email,gender');
} catch (FacebookApiException $e) {
$user = "";
}
}else {
$this->facebook->destroySession();
}
if($user!="")
{
$email = $user['email'];
$q = $this->db->select('email')->from('li_user')->where(array(
'email' => $email
))->get();
if ($q->num_rows() > 0) {
//update aja
$user_details = array(
'nama' => $user['name'],
'email' => $user['email'],
'user_status' => '1'
);
$this->session->set_userdata('user', $user);
$condition['email'] = $user['email'];
$this->model_register->updateuserbyfacebook($user_details,$condition);
// echo "you just update data";
}
else
{
$user_details = array(
'nama' => $user['name'],
'email' => $user['email'],
'user_status' => '1'
);
$this->session->set_userdata('user', $user);
$this->model_register->adduserbyfacebook($user_details);
// echo "you just insert data";
}
redirect(site_url('welcome')); //this redirect not giving me redirect
}
else
{
$data['login_url']= $this->facebook->getLoginUrl(array('redirect_uri' => site_url('register/loginfacebook'),
'scope' => array( "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
)));
$this->admin->load('template1', 'index', $data);
}
}
all works fine like charm but why after success login my controller doens't redirect the url stay,
i have tested in by echo with command works, but why my redirect doesn't redirect the page
Thanks for any words
Freddy Sidauruk
Did you try adding the refresh to see if it works? Also echo out the redirect and see if it is correct.
RE: after success login using API facebook not redirect to right controller - freddy - 11-06-2015
hello sorry late respond did you mean add refresh in here ?
Code: <?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Register extends CI_Controller
{
public function index()
{
$data['login_url']= $this->facebook->getLoginUrl(array('redirect_uri' => site_url('register/loginfacebook'),
'scope' => array( "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
)));
$data['login_google'] = $this->googleplus->loginURL(); //login google
$this->admin->load('template1', 'index', $data);
}
public function loginfacebook()
{
$user = "";
$userId = $this->facebook->getUser();
if ($userId) {
try {
$user = $this->facebook->api('/me?fields=id,name,link,email,gender');
} catch (FacebookApiException $e) {
$user = "";
}
}else {
$this->facebook->destroySession();
}
if($user!="")
{
$email = $user['email'];
$q = $this->db->select('email')->from('li_user')->where(array(
'email' => $email
))->get();
if ($q->num_rows() > 0) {
//UPDATE DATA USER
$user_details = array(
'nama' => $user['name'],
'email' => $user['email'],
'user_status' => '1'
);
$this->session->set_userdata('user', $user);
$condition['email'] = $user['email'];
$this->model_register->updateuserbyfacebook($user_details,$condition);
// redirect(site_url('welcome','refresh')); //this redirect not giving me redirect
}
else
{
//INSERT DATA USER
$user_details = array(
'nama' => $user['name'],
'email' => $user['email'],
'user_status' => '1'
);
$this->session->set_userdata('user', $user);
$this->model_register->adduserbyfacebook($user_details);
// redirect(site_url('welcome','refresh'));
// echo "you just insert data";
}
redirect(site_url('welcome','refresh')); //this redirect not giving me redirect
}
else
{
$data['login_url']= $this->facebook->getLoginUrl(array('redirect_uri' => site_url('register/loginfacebook'),
'scope' => array( "email, user_birthday, user_location, user_work_history, user_hometown, user_photos"
)));
$this->admin->load('template1', 'index', $data);
}
}
after adding refresh, the page facebook not redirect to welcome the page stay in facebook login without errors, please anyone guide me
RE: after success login using API facebook not redirect to right controller - InsiteFX - 11-07-2015
PHP Code: redirect(site_url('welcome'), 'refresh'); //this redirect not giving me redirect
From looking at the 3.0.x docs not sure if it still accepts the 'refresh'.
|