title: Facebook connect with codeigniter redirect in loop after login
body: <p>I am trying to connect facebook using codeigniter. If i am connecting fist time,then I can see permission popup but after I authorise permission i am getting multiple redirect loop error.</p>
  
  <p>If I am already logged in and authorised site then why it is not getting uid.</p>
  
  <p>I have give site url in facebook: <a href="http://mysite.com/" rel="nofollow">http://mysite.com/</a></p>
  
  <p>and my redirect uri is <a href="http://mysite.com/facebook/" rel="nofollow">http://mysite.com/facebook/</a></p>
  
  <p>I have added these files in my library folder.</p>
  
  <pre><code>library/fb_connect.php
  library/facebook/facebook.php
  library/facebook/base_facebook.php
  library/facebook/fb_ca_chain_bundel.crt
  </code></pre>
  
  <p>Last 3 files in facebook folder are facebook SDK files.</p>
  
  <p>Here is code in my fb_connect.php</p>
  
  <pre><code>&lt;?php
  include(APPPATH.'libraries/facebook/facebook.php');
  
   class Fb_connect {
  
  
  function connect(){
  
  
  $facebook = new Facebook(array(
      'appId'  =&gt; 'XXXXXXX',
      'secret' =&gt; 'XXXXXXXXXXXXXX',
      'cookie' =&gt; true,
   ));
  
      //Get User ID
    $user=$facebook-&gt;getUser();
  
    if(!$user){
     $loginUrl=$facebook-&gt;getLoginUrl(array(
      'scope'         =&gt; 'email,publish_stream,user_birthday,user_location',
      'redirect_uri'  =&gt; 'http://localhost/beta/facebook/',
      'display'=&gt; 'popup'
      ));
  
      redirect($loginUrl')";
      exit();
  
  
   } else {
  $user_profile = $facebook-&gt;api('/me');
  
   print_r($user_profile);
  
  }
   ?&gt;
  </code></pre>
  
  <p>And Here is my controller code:</p>
  
  <pre><code>function  facebook(){
  
    $this-&gt;load-&gt;library('fb_connect');
    $user_data=$this-&gt;fb_connect-&gt;connect();
  
   }
  </code></pre>