title: Facebook PHP SDK dealing with Access Tokens
body: <p>I have crawled around lots of various answers but am still a bit confused with how I should be dealing with facebook <strong>access tokens</strong>.
  One of the main problems I'm having is due to what information is being stored in my browser. For example, I log onto the app, the token expires, I can't logon again unless I clear cookies/app settings in browser. </p>
  
  <p>I stumbled across this thread: <a href="https://stackoverflow.com/questions/8982025/how-to-extend-access-token-validity-since-offline-access-deprecation">How to extend access token validity since offline_access deprecation</a></p>
  
  <p>Which has shown me how to create an extended access token through php.</p>
  
  <p><strong>My questions are:</strong></p>
  
  <p><strong>1.</strong> Do I need to store the access token anywhere?</p>
  
  <p><strong>2.</strong> What happens when the access token expires or becomes invalid? At the moment, my app simply stops working when the short term access ones expire. </p>
  
  <p><strong>3.</strong> Is there a way I should be handling them to check if they have expired?
  I am using the php sdk and have basically used the standard if( $user )... Like this:</p>
  
  <pre><code>require 'sdk/src/facebook.php';
  
    $facebook = new Facebook(array(
    'appId'  =&gt; 'XXXXXXXXXXXXXXXXXXXXX',
    'secret' =&gt; 'XXXXXXXXXXXXXXXXXXXXX',
  ));
  
    $user = $facebook-&gt;getUser();
  
    if( $user ){
      try{
          $user_profile = $facebook-&gt;api('/me');
      } catch (FacebookApiException $e) {
      error_log($e);
      $user = null;
      }
    }
  
    if (!$user){
  
      $params = array(
      'scope' =&gt; 'email',
      );
  
      $loginUrl = $facebook-&gt;getLoginUrl( $params );
          echo '&lt;script type="text/javascript"&gt; 
                  window.open("'. $loginUrl .'", "_self"); 
                  &lt;/script&gt;';
                  exit;
  
   } 
       if( $user ){
  
      $access_token = $facebook-&gt;getExtendedAccessToken();     
  
       $get_user_json = "https://graph.facebook.com/me?access_token=" 
         . $access_token;
  
  // Rest of my code here...
  }
  </code></pre>
  
  <ul>
  <li>Is there anything else I should be doing to handle tokens?</li>
  </ul>
  
  <p>. Should I be passing the access token between pages or is it ok to just call it again at the top of each page like this:</p>
  
  <pre><code>$facebook = new Facebook(array(
    'appId'  =&gt; 'XXXXXXXXXXXX',
    'secret' =&gt; 'XXXXXXXXXXXX',
    'redirect_uri' =&gt; 'http://localhost:8000/',
  ));
       $token = $facebook-&gt;getExtendedAccessToken();
  </code></pre>