title: Facebook OAUTH2 and PHP/JSDK
body: <p>I have registered with auth.login in order to do an ajax call back to my server and update login counts. it doesnt work as the php sdk is resolutely refusing to see that the user is properly logged in.</p>
  
  <p>JS code:</p>
  
  <pre><code>    window.fbAsyncInit = function () {
      var channelurl='http://'+window.location.hostname+'/channel.html';
          FB.init({
              appId : window.appid,
              status: true,
              cookie: true,
              xfbml: true,
              channelURL : channelurl, // channel.html file
              oauth  : true // enable OAuth 2.0
          });
          FB.Event.subscribe('auth.login', function (response) {
  
                     $("#fbconnecttext").html("&lt;a&gt;Logging in...&lt;/v&gt;");
  
                     $.ajax({
                        url: "fbupdatelogincount",
                        type: "GET",
                        cache: false,
                        success: function (html) {
                            window.setTimeout('$("#fbconnecttext").html("")', 10000);
                            var rec = JSON.parse(html);
                            window.numlogins = rec["numlogins"];
                            FB.api('/me', function (response) {
                               if (window.numlogins &gt; 1) {
                                   $("#fbconnecttext").html(window.welcomebacktext.replace("%s", response.first_name));
                                   $("#fbadminimg").attr("src", "common-images/smiley");
                               }
                               else {
                                   alert(window.firstlogintext.replace("%s", response.first_name));
                               }
  
                               });
  
                        }
                        });
                 });
  
          FB.Event.subscribe('auth.logout', function (response) {
                     $("#fbconnecttext").html(window.fbconnecttext);
                     $("#fb-like").show();
                     FB.XFBML.parse($('#fb-like').is());
                 });
          FB.Event.subscribe('auth.sessionChange', function (response) {});
      };
  
  (function(d){
       var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
       js = d.createElement('script'); js.id = id; js.async = true;
       js.src = "http://connect.facebook.net/en_US/all.js";
       d.getElementsByTagName('head')[0].appendChild(js);
     }(document));
  }
  </code></pre>
  
  <p>The php page</p>
  
  <pre><code>require_once("utils.php");
  logText("In  fbUpdatelogincount");
  if(fbAuthentication()){
      logText("authenticated in  fbUpdatelogincount");
      $r=fbUpdateStats();
      if(isset($_REQUEST["field"]))
          echo $r[$_REQUEST["field"]];
      else
          echo json_encode($r);
  }
  echo "";
  </code></pre>
  
  <p>And finally the fbAutentication code:</p>
  
  <pre><code>function fbAuthentication(){
  
      global $facebook;
      $facebook = new Facebook(array(
                       'appId' =&gt; getSetting("fb:app_id"),
                       'secret' =&gt; getSetting("fb:secret")
                       ));
      if($facebook-&gt;getUser()){
          try {
              global $fb_isadmin,$fb_me;
              $fb_me = $facebook-&gt;api('/me');
              $fb_isadmin=strstr(getSetting("fb:admins"),$facebook-&gt;getUser())!=false;
              fbUpdateStats();
              return true;
          } catch (FacebookApiException $e) {
              /* exception handling todo */
          }
          return true;
      }else logText("No Valid user");
  
      return false;
  
  }
  </code></pre>
  
  <p>The main issue is the ajax call firing up the url fbupdatelogincount but the PHP side saying "nope, no one is logged in". Any ideas? Same setup worked fine prior to 3.1.1</p>