title: Incorporating facebook login, using facebook php-sdk (v.3.0.0), with sessions and cookies
body: <p>I am new to PHP, and have had a very difficult time understanding the facebook login system. </p>
  
  <p>I have downloaded the three src/ files from github (https://github.com/facebook/php-sdk/). I tried using the example.php file to get me started. However, I am not sure what to do with it.</p>
  
  <p>For those who are unfamiliar with the file, here is a copy of example.php, with some of the styling removed: </p>
  
  <pre><code>require '../src/facebook.php';
  $facebook = new Facebook(array(
    'appId'  =&gt; '...',
    'secret' =&gt; '...',
  ));
  $user = $facebook-&gt;getUser();
  if ($user) {
    try {
      $user_profile = $facebook-&gt;api('/me');
    } catch (FacebookApiException $e) {
      error_log($e);
      $user = null;
    }
  }
  if ($user) {
    $logoutUrl = $facebook-&gt;getLogoutUrl();
  } else {
    $loginUrl = $facebook-&gt;getLoginUrl();
  }
  $naitik = $facebook-&gt;api('/naitik');
  ?&gt;
  &lt;!doctype html&gt;
  &lt;html xmlns:fb="http://www.facebook.com/2008/fbml"&gt;
    &lt;body&gt;
      &lt;?php if ($user): ?&gt;
        &lt;a href="&lt;?php echo $logoutUrl; ?&gt;"&gt;Logout&lt;/a&gt;
      &lt;?php else: ?&gt;
        &lt;div&gt;
          Login using OAuth 2.0 handled by the PHP SDK:
          &lt;a href="&lt;?php echo $loginUrl; ?&gt;"&gt;Login with Facebook&lt;/a&gt;
        &lt;/div&gt;
      &lt;?php endif ?&gt;
  
      &lt;h3&gt;PHP Session&lt;/h3&gt;
      &lt;pre&gt;&lt;?php print_r($_SESSION); ?&gt;&lt;/pre&gt;
  
      &lt;?php if ($user): ?&gt;
        &lt;h3&gt;You&lt;/h3&gt;
        &lt;img src="https://graph.facebook.com/&lt;?php echo $user; ?&gt;/picture"&gt;
  
        &lt;h3&gt;Your User Object (/me)&lt;/h3&gt;
        &lt;pre&gt;&lt;?php print_r($user_profile); ?&gt;&lt;/pre&gt;
      &lt;?php else: ?&gt;
        &lt;strong&gt;&lt;em&gt;You are not Connected.&lt;/em&gt;&lt;/strong&gt;
      &lt;?php endif ?&gt;
  
      &lt;h3&gt;Public profile of Naitik&lt;/h3&gt;
      &lt;img src="https://graph.facebook.com/naitik/picture"&gt;
      &lt;?php echo $naitik['name']; ?&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here are the questions I have in regard to it:</p>
  
  <p>1)What about cookies?--I want the user to be able to be logged into my website after re-opening his/her browser.</p>
  
  <p>2)What is the bare minimum I need to get out of this example.php file to validate/register a user, begin a session, store the session in a cookie, get the user's fb user id, fb name, fb picture, and list of fb friends?</p>
  
  <p>3)In the src/ files, there is one 'file fb_ca_chain_bundle.crt,' and I am completely unfamiliar with what such a file, and I am not sure if it is even necessary. What is its purpose?</p>
  
  <p>4)The line <code>$naitik = $facebook-&gt;api('/naitik');</code> is "naitik" the username of this person--so if I type facebook.com/naitik it will show his public profile? is replacing "/naitik" with "/me" what will get the public profile of the person logged into facebook?</p>
  
  <p>5)How do I get the access token, and how do I use it in my code?</p>
  
  <p>6)When I create a session for the user, and a cookie so that the user is logged in after reopening the browser, what should I exactly be storing in my sessions and cookies?</p>
  
  <p>I know this is many questions, but I have looked through many tutorials online, and none of them have done a good job explaining this, mostly because they just link back to the Github PHP-SDK files. Plus, most of them explain a previous version of PHP-SDK. 
  Any help is appreciated, with any of the questions.</p>