title: Facebook authentication with codeigniter (active access token must...)
body: <p>I sign in with FB fine if I directly create a page at domain.com/someurl.php
  The moment I copy the same code (inc html) into a view file with codeigniter and go to domain.com/login/someurl.html it doesn't work. By it doesn't work I mean, I get an exception if i try to access /me after signing into facebook.</p>
  
  <p>The message reads "An active access token must be used to query information about the current user"...
  In my controller  i have my index function and all it does is load the view with the facebook login code.</p>
  
  <p>I thought I may be doing something wrong but I copied the sample.php from the facebook sdk and paste it into the view file and the same thing happens. If i copy the sample code into the file at someurl.php it then works as expected...given the situation I suspected it may be something to do with codeigniter and possibly some config option I have that causes that behaviour...</p>
  
  <p>I've been looking up the error for a while now and have found a few resources:
  <a href="http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/" rel="nofollow noreferrer">http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2705756/facebook-access-token-invalid">Facebook access_token invalid?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5938887/facebook-authentication-issue">Facebook authentication issue</a></p>
  
  <p><a href="https://github.com/facebook/php-sdk/wiki/AccessToken" rel="nofollow noreferrer">https://github.com/facebook/php-sdk/wiki/AccessToken</a>
  but none of the suggested fixes have worked.</p>
  
  <p>Right from the sample:</p>
  
  <pre><code>// Create our Application instance (replace this with your appId and secret).
  $facebook = new Facebook(array(
    'appId'  =&gt; 'APPID',
    'secret' =&gt; 'SHHHH',
  ));
  
  // Get User ID
  $user = $facebook-&gt;getUser();
  
  // We may or may not have this data based on whether the user is logged in.
  //
  // If we have a $user id here, it means we know the user is logged into
  // Facebook, but we don't know if the access token is valid. An access
  // token is invalid if the user logged out of Facebook.
  
  if ($user) {
    try {
      // Proceed knowing you have a logged in user who's authenticated.
      $user_profile = $facebook-&gt;api('/me');
    } catch (FacebookApiException $e) {
      error_log($e);
      $user = null;
    }
  }
  
  // Login or logout url will be needed depending on current user state.
  if ($user) {
    $logoutUrl = $facebook-&gt;getLogoutUrl();
  } else {
    $loginUrl = $facebook-&gt;getLoginUrl();
  }
  </code></pre>
  
  <p>It doesn't work in the view and I'm stumped as to why or why none of the fixes or "precautions" such as not using type or ensuring the redirect url is the same etc, work.</p>
  
  <p><strong>EDIT:</strong>
  I'm trying to avoid using domain.com/somefile.php and instead use a view file like every other page...</p>