title: Login using facebook api
body: <p>I have code like below. Why <code>$userId</code> is always <code>0</code>? When I click Login button I get <code>B.login() called when user is already connected.</code>. When I check allowed apps in fb, this app is added. It looks like I'm connected so it should be my <code>id</code> instead of <code>0</code>.</p>
  
  <pre><code>&lt;pre&gt;
  define('YOUR_APP_ID', ###);
  
  require 'facebook.php';
  
  $facebook = new Facebook(array(
    'appId'  =&gt; ###,
    'secret' =&gt; '###',
  ));
  
  $userId = $facebook-&gt;getUser();
  echo $userId;
  ?&gt;
  
  &lt;html&gt;
    &lt;body&gt;
      &lt;?php if ($userId) { 
        $userInfo = $facebook-&gt;api('/' + $userId); ?&gt;
        Welcome &lt;?= $userInfo['name'] ?&gt;
      &lt;?php } else { ?&gt;
      &lt;div id="fb-root"&gt;&lt;/div&gt;
      &lt;fb:login-button&gt;&lt;/fb:login-button&gt;
      &lt;?php } ?&gt;
      &lt;script&gt;
        window.fbAsyncInit = function() {
          FB.init({
            appId      : '&lt;? echo('####'); ?&gt;',
            status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true,
          });
  
          FB.Event.subscribe('auth.login', function(response) {
            window.location.reload();
          });
        };
  
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p></p>