Welcome Guest, Not a member yet? Register   Sign In
after success login using API facebook not redirect to right controller
#2

(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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: after success login using API facebook not redirect to right controller - by InsiteFX - 11-06-2015, 05:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB