Get notified about the status of a Facebook user in your web app using periodic Ajax calls.


 This article is helpful only if you have the following situation:
 A web app which uses facebook login to login its users and if a user is logged out from his/her facebook account through another browser tab, then your app dont know that he is logged out  out or not from his facebook account and he/she will remain as logged in your web application.Its ok if you have no problem with this situation.But if you want to forcefully logout the user from your application if he is logged out from his facebook account means you can try this example.This example uses periodic ajax calls to facebook's graph api to check whether the user is logged in or not.
<script type="text/javascript">

  var loginStatus=null;
      window.fbAsyncInit = function() {
          appId      : "<?php echo Yii::app()->params['facebook_appId'] ?>",
          status     : true, 
          cookie     : true,
          xfbml      : true,
          oauth      : true,
             /*This will work only at onload*/
               FB.getLoginStatus(function(response) {
                                if (response.status === 'connected') {


        /*The function used for ajax calls */
        function checkStatus()
           FB.api('/me', function(response) {
              var isGuest="<?php if (Yii::app()->user->isGuest) echo 'true'; else echo 'false'; ?>";

                 window.location="<?php echo Yii::app()->createAbsoluteUrl('site/logout'); ?>";


         var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
         js = d.createElement('script'); = id; js.async = true;
         js.src = "//";


I have posted a working code above.anyway let me know if you have any problem with this. -Sirin