title: Check if Facebook User logged in without PHP SDK
body: <p>I’m trying to emulate the Facebook login workflow by a self-written code (i.e. without using the Facebook PHP SDK), according to Facebook documentation this should be possible and quite simple:</p>
  
  <blockquote>
    <p>“Apps using our SDKs can check whether someone has already logged in
    using built-in functions. All other apps must create their own way of
    storing when a person has logged in”</p>
  </blockquote>
  
  <p><a href="https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.2" rel="nofollow">https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.2</a></p>
  
  <p>My main motivation is that the frequent changes by Facebook and the SDKs are frustrating and urging me to migrate to native HTTP requests with self written libraries.</p>
  
  <p>When using the SDK, process should be (this is with previous version):</p>
  
  <pre><code>$facebook = new Facebook(array(
      'appId'     =&gt; MY_APP_ID,
      'secret'    =&gt; MY_APP_SECRET,
      ));
  $this_user_facebook_id = $facebook-&gt;getUser(); // Get User ID
  if($this_user_facebook_id &gt; '0')
      {
      try
          {
          $user_access_token = $facebook-&gt;getAccessToken();
          // do whatever you like
          }
      }
  catch(FacebookApiException $e)
      {
      print_r($e);
      $this_user_facebook_id = NULL;
      }
  </code></pre>
  
  <p>The process I’m trying to follow is:</p>
  
  <ul>
  <li>CURL to
  <a href="https://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&amp;redirect_uri=FACEBOOK_REDIRECT_URL&amp;scope=MY_APPROVED_SCOPE" rel="nofollow">https://www.facebook.com/dialog/oauth?client_id=MY_APP_ID&amp;redirect_uri=FACEBOOK_REDIRECT_URL&amp;scope=MY_APPROVED_SCOPE</a></li>
  <li>Scrape the redirect URL - if it includes a "code=..." $_GET variable, it means that the user is logged in, and I could query the
  access_token. Otherwise, present a Facebook Login link</li>
  </ul>
  
  <p>Issue is that I get dropped at this stage: I tried to read the Facebook redirect header until a realised that actually Facebook redirect the user with meta tags:</p>
  
  <pre><code>&lt;meta http-equiv="refresh" content="0;url=https://www.facebook.com/login.php?skip_api_login=1&amp;amp;api_key=............ ------LONG FACEBOOK URL -------&gt;
  </code></pre>
  
  <p>Issue is that I couldn't find the native URL there, i.e. the code=.... variable is missing even that the user <strong>does get</strong> redirected to <code>http://MY_APP_REDIRECT_URL/?code=</code></p>
  
  <p>I tried to read the CURL header but there is nothing there. I also tried to generate the APP access token and query the user access token through it (failed).</p>
  
  <p>Any clues? Any ideas how to generate a native HTTP Graph API request that would lead to query the user access_token? I'm three days on the net trying to figure this out and the Facebook documentation is not so helpful as well.</p>