title: Login with Facebook without database
body: <p>I'm trying to create a website that allows users to login with their Facebook account. I do not need to make any requests or store any info when they are not on the website and so I do not need a database.</p>
  
  <p>I am only going to accept login with Facebook and no other login types are required. I will need the typical login with Facebook button on the login page and the ability to keep them logged in across multiple pages. I would also like to add an ability to log out.</p>
  
  <p>I've downloaded the PHP SDK and I am using the JavaScript SDK together on my pages, but I am having so much trouble.</p>
  
  <p>Is it just me or does the Facebook SDK completely suck?</p>
  
  <p>My first problem is that the JavaScript SDK on the login page doesn't redirect the user to the main page after authentication. I am manually refreshing the page currently (the PHP SDK realizes that the user is logged in and sends the user to the main page).</p>
  
  <p>Another issue is logout. I am using the PHP SDK's getLogoutURL() function, and it logs the user out of Facebook, but my access token is still fully valid and PHP refuses to send the user to the login page. Why? I have no idea. Personally, I'd like that the user be logged out of my website and not Facebook.</p>
  
  <p>I'm trying to make a seamless login system with Facebook, but I'm having nothing but trouble! I can't seem to find any good documentation on Facebook Connect at all. I'm using their examples and problems like this are happening. Maybe they just can't make a good SDK. I'd like to use the PHP SDK and the JavaScript SDK to make a very nice user experience, but it just doesn't seem possible.</p>
  
  <p>login.php's PHP code
      
  
  <pre><code>require_once("../fb-sdk/src/facebook.php");
  
  $Facebook = new Facebook(array(
    'appId'  =&gt; 'xx',
    'secret' =&gt; 'xx',
  ));
  
  $User = $Facebook-&gt;getUser();
  
  if ($User)
  {
    try
    {
      // Proceed knowing you have a logged in user who's authenticated.
      $UserProfile = $Facebook-&gt;api("/me");
    } catch (FacebookApiException $e) {
      error_log($e);
      $User = null;
    }
  }
  
  if ($User)
  {
    header("Location: index.php");
  }
  
  ?&gt;
  </code></pre>
  
  <p>login.php's JavaScript code</p>
  
  <pre><code>&lt;div id="fb-root"&gt;&lt;/div&gt;
  &lt;script&gt;
    window.fbAsyncInit = function() {
      FB.init({
        appId      : 'xx', // App ID
        channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
      });
    };
    // Load the SDK Asynchronously
    (function(d){
       var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
       if (d.getElementById(id)) {return;}
       js = d.createElement('script'); js.id = id; js.async = true;
       js.src = "//connect.facebook.net/en_US/all.js";
       ref.parentNode.insertBefore(js, ref);
     }(document));
  &lt;/script&gt;
  &lt;div class="fb-login-button"&gt;Login with Facebook&lt;/div&gt;
  </code></pre>
  
  <p>index.php's PHP code
      
  
  <pre><code>require_once("../fb-sdk/src/facebook.php");
  
  $Facebook = new Facebook(array(
    "appId"  =&gt; "xx",
    "secret" =&gt; "xx",
  ));
  
  $User = $Facebook-&gt;getUser();
  
  if ($User)
  {
    try
    {
      // Proceed knowing you have a logged in user who's authenticated.
      $UserProfile = $Facebook-&gt;api("/me");
    } catch (FacebookApiException $e) {
      error_log($e);
      $User = null;
    }
  }
  
  if (!$User)
  {
    header("Location: login.php");
  }
  
  ?&gt;
  </code></pre>